how to read a text file using dlmread that is not in matlab directory?

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

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

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.
You need to remove '{' '}' symbols. The correct is
dlmread('C:\path_to_folder\ann.txt')
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.
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.
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?
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')

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!