Reading formatted data from a file

1 回表示 (過去 30 日間)
Mahi Nazir
Mahi Nazir 2015 年 5 月 20 日
編集済み: dpb 2015 年 5 月 20 日
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 件のコメント
Thorsten
Thorsten 2015 年 5 月 20 日
Please provide the file such that we can have a close look.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by