how to read a text file using dlmread that is not in matlab directory?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Hi there... how to solve this error "Error using dlmread (line 122) The file 'an.text' could not be opened because: No such file or directory", as my file is located at desktop in text format. kidnly help me out to read data in this file. thanks in advance
Accepted Answer
Ameer Hamza
on 11 Aug 2018
If it is not on MATLAB path, you can still read it by specifying the correct Absolute or relative paths. For example, the following uses an absolute path
dlmread('C:\{path_to_folder}\ann.txt')
Where 'C:' is the drive in which folder is located. Similarly, on Mac or Linux, you will need respective absolute paths.
8 Comments
Saba Yousaf
on 11 Aug 2018
thanks #Ameer_Hamza for your valueable answer. but again getting this error "Error using dlmread (line 62) The file 'C:\{Users\Annaya\Desktop}\an.txt' could not be opened because: No such file or directory" after specifying path.
Ameer Hamza
on 11 Aug 2018
You need to remove '{' '}' symbols. The correct is
dlmread('C:\path_to_folder\ann.txt')
Saba Yousaf
on 11 Aug 2018
Thank you so much sir. now it works. can you tell me please if i want to save this "ann.txt" file in matlab directory then what protocols i have to fellow. thanks once more.
Ameer Hamza
on 11 Aug 2018
You can place it any folder that is in MATLAB path. For example type
cd(userpath)
in MATLAB and it will take you to the MATLAB base directory. You can paste 'ann.txt' file in that directory and it from next time you can read it without specifying the full path. Similarly, you can use
pathtool
to add a directory in MATLAB's path.
Saba Yousaf
on 11 Aug 2018
done thank you
Saba Yousaf
on 11 Aug 2018
In this attachment first row contains the characters then how can i specify them in syntax "dlmread(filename, delimiters, r1 c1)" to read all data?
Ameer Hamza
on 11 Aug 2018
dlmread() can't read non-numeric data. In your file, the first column contains dates. For you case, more appropriate is
data = readtable('an.txt')
Saba Yousaf
on 11 Aug 2018
oky.
More Answers (0)
Categories
Find more on Standard File Formats in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)