Problems with fscanf

조회 수: 11 (최근 30일)
Ricardo
Ricardo 2011년 5월 14일
[EDIT: Sat May 14 02:19:15 UTC 201 - Reformat - MKF]
Why is this wrong ?
fid = fopen ('dados.txt', 'r');
dados = fscanf(fid, '%g %g', [9 inf]);
fclose (fid);
dados = dados' ;
This is what I have at my "dados" file:
20000 218.66 224.29 222.77 99.42 96.92 97.58 0.81 2.59
... A (3000x9) matrix with numbers like that
And this is what MATLAB suggests :
??? Error using ==> fscanf
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in ==> programa at 2
dados = fscanf(fid, '%g %g', [9 inf]);
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 5월 14일
Note: you will want
dados = fscanf(fid, '%g', [9 inf]) .';
if you want the resulting matrix to be row-oriented like the input is.

댓글을 달려면 로그인하십시오.

채택된 답변

Ricardo
Ricardo 2011년 5월 14일
Hahaha, sorry, but I found the answer, the guy who has sent me the file saved it as "dados.txt" so the name of the file isn´t only "dados".
  댓글 수: 2
Walter Roberson
Walter Roberson 2011년 5월 14일
but in your problem statement, you are opening dados.txt already ?
Matt Fig
Matt Fig 2011년 5월 14일
I think Ricardo means that the full name of the file, including extension is:
dados.txt.txt

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt Fig
Matt Fig 2011년 5월 14일
For some reason FOPEN did not find dados.txt. Is it in your current directory?
  댓글 수: 1
Ricardo
Ricardo 2011년 5월 14일
Yes.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile 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!

Translated by