Problems with fscanf
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
[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 comentario
Walter Roberson
el 14 de Mayo de 2011
Note: you will want
dados = fscanf(fid, '%g', [9 inf]) .';
if you want the resulting matrix to be row-oriented like the input is.
Respuesta aceptada
Ricardo
el 14 de Mayo de 2011
2 comentarios
Walter Roberson
el 14 de Mayo de 2011
but in your problem statement, you are opening dados.txt already ?
Matt Fig
el 14 de Mayo de 2011
I think Ricardo means that the full name of the file, including extension is:
dados.txt.txt
Más respuestas (1)
Matt Fig
el 14 de Mayo de 2011
For some reason FOPEN did not find dados.txt. Is it in your current directory?
Ver también
Categorías
Más información sobre Data Type Identification en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!