Please provide the file such that we can have a close look.
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
回答(0 个)
另请参阅
类别
在 Help Center 和 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!