Monday, 15 June 2015

file - Matlab- Reading irregular textfile -



file - Matlab- Reading irregular textfile -

how can read textfile containing next text in matlab?

b4070ic05.tif,11 b4070ic06.tif,11,15,16,6,7 b4070ic07.tif,13,14,4,18,9 b4070ic08.tif,10,7 b4070ic09.tif,4,22,7 b4070ic10.tif,14,15,19,20,24,29,9 b4070ic11.tif,10,11,20,21 b4070ic12.tif,13,14,5,9

i don't know number of columns of text.

is there way set these info in cell matrix? how can print cell matrix after info load?

you can utilize textscan this. create sure number of %f-s long plenty cover longest series of values in file. if numeric values integer, utilize instance `%d' (see textscan more details).

fid = fopen(filename); = textscan(fid,'%s %f %f %f %f %f %f %f','delimiter',','); fclose(fid);

the result cell array, first column strings 'blabla.tif' , sec lastly column numeric values. if value not nowadays in file, equals nan.

accessing j-th value of i-th column done a{i}(j).

by way, lastly line in file not appended nans, other lines. means combining result cell array not straight possible: lastly few arrays (might be) shorter first. did not find obvious prepare that, have manually:

idx = find(diff(arrayfun(@(idx)numel(a{idx}),1:numel(a)))); ca = [a{1} num2cell([horzcat(a{2:idx}) [horzcat(a{idx+1:end});nan(1,numel(a)-idx)]])];

matlab file text

No comments:

Post a Comment