Reading formatted data from a file
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a file containing data like:
Blocks=N
The position is -8,5, velocity is 1 and direction is 0 deg
1.7 2 3 4
5 6.2 7 8
9 0 1 2.4
3 4 5 6.2
The position is -8,10, velocity is 1 and direction is 5 deg
5.2 8 9 4
1 5 7 4.1
4 9 6 3
8 2 4 6
and so on..... till.... N
To read this data I am using:
inputfile1=sprintf('AmbgFunc for all positions all velocities');
fid=fopen(inputfile1,'r');
blocks_ip = fscanf(fid, 'blocks=%d\n', 1);
for i=1:blocks
mystruct(i).position = fscanf(fid, '%*s %*s %*s %f,%f, %*s %*s %f %*s %*s %*s %f %*s\n', 4)';
position=mystruct(i).position
mystruct(i).Matrix = fscanf(fid, '%f', [4,4])';
Mat(:,:,i)=mystruct(i).Matrix
end
It's correctly reading the position from the header which is [-8,5 1 0] but it is not reading the matrix and hence in the second loop the position is read wrong (one of the matrix value is read instead). Any help would be appreciated. Thanks
댓글 수: 1
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!