0
我希望能夠導入包含46行標題,然後是4 x6列數據的文件。我試圖從以前的答案中使用這個例子,但是textscan不能工作。Matlab跳過overheader導入文本文件(後續)
這是我的測試文件:ImportTest.txt
1.0 2.0 3.0 1.1 2.1 3.1 1.2 2.2 3.3
下面是代碼。 strData大小不同。爲什麼?
%open file
fid = fopen('ImportTest.txt');
strData = textscan(fid,'%s%s%s%s', 'Delimiter',',')
fclose(fid);
%# catenate, b/c textscan returns a column of cells for each column in the data
strData = cat(2,strData{:}) ;
%# convert cols 3:6 to double
doubleData = str2double(strData(:,3:end));
%# find header rows. headerRows is a logical array
headerRowsL = all(isnan(doubleData),2);
%# since I guess you know what the headers are, you can just remove the header rows
dateAndTimeCell = strData(~headerRowsL,1:2);
dataArray = doubleData(~headerRowsL,:);
%# and you're ready to start working with your data