fscanf to read a file which contains an intensity image

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)

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.
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

Categories

Find more on Convert Image Type in Help Center and File Exchange

Asked:

on 8 Dec 2012

Community Treasure Hunt

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

Start Hunting!