Missing something obvious? (fscanf)
古いコメントを表示
Trying to use fscanf to read data from a file that is 24 rows by 5 columns. I've set up this:
[fileId,errorMsg] = fopen('Data.txt', 'r');
if fileId < 0
disp(errorMsg);
else
NUMROWS = 24;
for row = 1:NUMROWS
for col = 1:5
data(row,col) = fscanf(fileId, '%d', inf);
end
end
end
but I keep getting a "Subscripted assignment dimension mismatch." error when I run it. Not sure if I'm missing some obvious error or if I'm just doing this wrong to begin with.
Thanks very much for your help in advance.
4 件のコメント
Cedric
2013 年 3 月 21 日
Could you copy/paste this file here as a comment? The FSCANF won't work a priori, and I guess that we should discuss the approach.
If you do the following, you should see that it cannot work
>> [fileId,errorMsg] = fopen('Data.txt', 'r') ;
>> fscanf(fileId, '%d', inf)
ans =
.. whatever you'll get
>> fscanf(fileId, '%d', inf)
ans =
.. and here it should start not to return what you want ..
>> fscanf(fileId, '%d', inf)
ans =
.. and again ..
>> fscanf(fileId, '%d', inf)
ans =
.. and again ..
...
Ian Barker
2013 年 3 月 21 日
Image Analyst
2013 年 3 月 21 日
Is the file text, or binary?
Ian Barker
2013 年 3 月 21 日
採用された回答
その他の回答 (1 件)
Image Analyst
2013 年 3 月 21 日
0 投票
You can only assign one value to data(row,col) so why do you have inf instead of 1? Anyway, why don't you just use fread() to read the whole stream of data into a 2D array directly? Why use fscanf()?
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!