Generating a matrix after importing data from csv file with fgets in matlab

本小妞迷上赌 提交于 2019-12-12 00:44:29

问题


I need to generate a matrix (30x900) of data (for complex analysis) after reading said data from a csv (text) file. I can read the data in to matlab using fgets, unfortunately I can't use load as the data has a header. The files look like this:

872
30
FR

(Data below here needs to be put in to matrix)

0000.0 0000.0 0000.0
0001.0 0000.0 0000.0
0002.0 0000.0 0000.0

Is it possible to do this?


回答1:


Use csvread instead.

filename = 'file.txt';
numberOfLinesInHeader = 3;
M = csvread(filename, numberOfLinesInHeader, 0);



回答2:


I suggest you to take a look at importdata too. It's a very easy to use and high level function. Here is the forth syntax:

del = ' '; % Delimiter
nHl = 5; % Number of header lines
dat = importdata('text.txt', del, nHl)

Now dat is a structure; dat.data contains data and header goes in dat.textdata.



来源:https://stackoverflow.com/questions/17731851/generating-a-matrix-after-importing-data-from-csv-file-with-fgets-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!