Monday, 15 September 2014

matlab - reading in a file with textscan and ignoring certain lines -



matlab - reading in a file with textscan and ignoring certain lines -

i have input file has rows of integers this:

1 2 3 4 5 6 7 8 9

i want read in file, have used textscan function kind of task before. there few lines in info (at random positions) contain double numbers, example

<large number of integer lines> 0.12 12.44 65.34 <large number of integer lines>

when reading in file, want ignore these lines. what's best approach this? can tell textscan ignore patterns?

assuming don't know location , number of lines floats, , don't want lines such 1.0 2.0 3.0 or 1 2 3.0 thought read file line line , not store lines contain . character.

fid = fopen('file.txt'); nums = []; line = fgetl(fid); while line ~= -1 % #read until end of file if isempty(strfind(line, '.')) line = textscan(line, '%d %d %d'); nums = [nums; line{:}]; end line = fgetl(fid); end fclose(fid);

nums matrix containing data.

matlab

No comments:

Post a Comment