简体   繁体   English

如何从libreoffice导入数据到Matlab

[英]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. 我在Lib-re Office 3.5中有一个文件,该文件仅包含1行但包含数千个数据。 How do import this in Matlab? 如何在Matlab中导入呢? I tried with making the file become .DAT extension but obtained the following error: ">> filename='z.dat'; 我尝试使文件成为.DAT扩展名,但出现以下错误:“ >> filename ='z.dat';

M=csvread(filename) Error using csvread (line 37) File not found." M = csvread(filename)使用csvread时出错(第37行)找不到文件。”

the solution is to save in csv file. 解决的方法是保存在csv文件中。 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.. 但是我的问题是我看不到我的数据,记住我对Matlab来说还很陌生..因此使用命令可以完美地工作。

    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. 尽管csvread方法适用于.dat文件,但如其他人所建议的那样,最好以.csv格式保存文件。 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: 因此,如果名为z.csv的文件位于/usr/local/MATLAB/R2011b/bin ,则应编写以下代码:

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. 这将自动确保您访问正确的文件,即使您可能不在MATLAB中的正确文件夹中也是如此。 Even if you do not see your file by typing ls your code will still access it. 即使您通过输入ls看不到文件,您的代码仍然可以访问它。 Do make sure to update the path if you change it though. 如果要更改,请确保更新路径。

Have a look to fread . 看一下第FREAD This function can load .dat or .bin as you want. 该函数可以根据需要加载.dat或.bin。 Be sure to pass type you want to load. 确保传递您要加载的类型。 Like uint8=>uint8 will read the value in uint8 and save under uint8 in matlab. 就像uint8=>uint8将读取uint8=>uint8的值并保存在matlab的uint8下。 You don't need to specify the =>uint8 , but it increase the performance. 您无需指定=>uint8 ,但它可以提高性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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