问题
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