简体   繁体   中英

how to import data from libreoffice into Matlab

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."

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..:)

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM