Although the method csvread
works with .dat
files, it is better to save your file in .csv
format, as other people have suggested. My answer is related to the error that you are getting in your code which is the "file not found" error.
It is always better to mention the full path to the file that you want to read. So if your file named z.csv
exists at /usr/local/MATLAB/R2011b/bin
then you should write the following code:
filename = '/usr/local/MATLAB/R2011b/bin/z.csv';
M = csvread(filename);
This will automatically ensure that you access the correct file even though you might not be in the correct folder in MATLAB. Even if you do not see your file by typing ls
your code will still access it. Do make sure to update the path if you change it though.