fscanf to read a file which contains an intensity image

1 view (last 30 days)
Hello, I need to read a file that contains an double/float matrix in format
1, 1, 0.00, 0.00, 0.00, 2426
(.....)
248, 256, 0.00, 0.00, 0.00, 1839
 
problem is that in the first 142 lines, there are strings which i have to ignore, and I'm not getting fscanf to work. Im not allowed to use textscan This is how im calling fscanf:
A = fscanf(fid, '%f %f %f %f %f %f', [6, inf])
In help fscanf, it says that the lines that arent in the specified format will be ignored, but that doesn't happen
Reply please, thank you!

Answers (2)

Walter Roberson
Walter Roberson on 8 Dec 2012
Where do you see that in the help for fscanf? The documentation says,
If fscanf cannot match the format to the data, it reads only the portion that matches into A and stops processing.

Jan
Jan on 8 Dec 2012
How to skip 142 lines:
fid = fopen(FileName, 'r');
if fid == -1, error('Cannot open file: %s', FileName); end
for k = 1:142
fgets(fid);
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!