Reading formatted data from a file
Show older comments
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 Comment
Thorsten
on 20 May 2015
Please provide the file such that we can have a close look.
Answers (0)
Categories
Find more on Workspace Variables and MAT Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!