reading text data with multiple headings in matlab -
i trying read text file in matlab has data stored follows multiple tests:
x1 x2 y 1 2 5 2 4 7 3 2 1 ... x1 x2 y 5 6 8 2 9 0 3 6 7 ... x1 x2 y -1 4 3.5 6.4 3.6 3 3 6 7.4 ...
how go reading in matlab if have column headings repeated multiple times? tried using importdata read first heading , data associated first heading.
thanks help!
here idea, bit clumsy working:
create temporary array rows:
fid=fopen('yourfile.txt'); rows = textscan(fid,'%s', 'delimiter','\n'); fclose(fid);
look start of each dataset detecting x
character:
datastarts=strfind(rows{1,1},'x'); dataidx = find(~cellfun('isempty', datastarts));
now can extract rows using intervals between indices in dataidx
.
columns= cellfun(@(x) textscan(x,'%f','delimiter','\t','collectoutput',1), rows{1,1}); columns= cellfun(@transpose, columns, 'uniformoutput', 0); j=1:size(dataidx)-1 data{j}=cell2mat(columns(dataidx(j)+1:dataidx(j+1)-1)); end data{j+1}=cell2mat(columns(dataidx(size(dataidx))+1:size(rows{1,1})));
the individual data sets stored in cell array data
.
data = [3x3 double] [3x3 double] [3x3 double]
Comments
Post a Comment