1

I have a file in Lib-re Office 3.5, which contain only 1 row but with thousands of data. How do import this in Matlab? I tried with making the file become .DAT extension but obtained the following error: ">> filename='z.dat';

M=csvread(filename) Error using csvread (line 37) File not found."

Zay
  • 115
  • 2
  • 6
  • Are you in the right directory? If you type `ls` in the command window do you see "z.dat" in the results? Also note that the file name is case sensitive. – Bonlenfum Sep 27 '13 at 07:58
  • 2
    As I already told you in your other question (http://stackoverflow.com/questions/19020238/how-to-generate-the-weibull-parameters-k-and-c-in-matlab/19022464), save your spreadsheet as a csv file and import your data using `csvread`. Make sure the *.csv file exists and MATLAB can find it. – am304 Sep 27 '13 at 08:40
  • no i cannot see the z.dat when i do ls.. – Zay Sep 27 '13 at 09:28
  • i am in >> cd /usr/local/MATLAB/R2011b/bin directory .. – Zay Sep 27 '13 at 09:30

3 Answers3

1

the solution is to save in csv file. But my problem is i was not able to see my data, remember I am very new to Matlab.. hence with the commands it work perfectly..

    filename='z';
M=csvread(filename)

 #i obtain my list of data,, now i have to eliminate all zeros. hence,

M=M(M~=0)

then all is fine..:)

Zay
  • 115
  • 2
  • 6
1

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.

ammportal
  • 991
  • 1
  • 11
  • 27
0

Have a look to fread. This function can load .dat or .bin as you want. Be sure to pass type you want to load. Like uint8=>uint8 will read the value in uint8 and save under uint8 in matlab. You don't need to specify the =>uint8, but it increase the performance.

Vuwox
  • 2,331
  • 18
  • 33