fscanf not giving any output
이전 댓글 표시
Attached below is the current code I have
fid = fopen('sample_velmod.txt','r');
formatspec = '%d %d\n';
sizeA = [2 inf];
A = fscanf(fid,formatspec,sizeA);
fclose(fid);
However, when I run this, I get no output for A. The text file has been implemented into the matlab directory so I know that it is reading the file fine. Any help getting and output for A would be great.
채택된 답변
추가 답변 (1개)
Walter Roberson
2022년 9월 4일
1 개 추천
fscanf() will return empty under either of two conditions:
- the file is empty; OR
- the data at the file position does not match the first element of the format specification.
For example, the format that you used would fail if there is a header line on the file, unless you read the header line first.
I would suggest that you use readmatrix() as readmatrix() will automatically detect and discard a header line if present.
댓글 수: 2
Walter Roberson
2022년 9월 4일
Your file contains, for example,
1100.00 3366.58
Those are not integers.
Also, your file has tab characters in it, and carriage returns. You need
formatspec = '%f\t%f';
Jacob Allen
2022년 9월 4일
카테고리
도움말 센터 및 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!