fscanf to read a file which contains an intensity image
1 次查看(过去 30 天)
显示 更早的评论
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!
回答(2 个)
Walter Roberson
2012-12-8
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.
0 个评论
Jan
2012-12-8
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!