How to read only the first term on the file.

1 回表示 (過去 30 日間)
Moises Belda
Moises Belda 2019 年 5 月 31 日
コメント済み: Moises Belda 2019 年 6 月 17 日
Hi, I would know if someone can help me with this. In the file I have, I only need to read te first term of the second column, I mean, the total_x number. Anyone know how can I do that?
Thanks
  7 件のコメント
Moises Belda
Moises Belda 2019 年 5 月 31 日
No, just only -1.781235e-01. I only need this term of all columns.
Thanks
Moises Belda
Moises Belda 2019 年 6 月 17 日
I again,
Could you help me once more, please. In the previous question I needed the first term of the first row, but instead of that now I need the third term, how could I obtain them? I am a bit lost with all the %f and %s...
Thank you

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

採用された回答

per isakson
per isakson 2019 年 5 月 31 日
編集済み: per isakson 2019 年 5 月 31 日
Try this
%%
ffs = 'h:\m\cssm\force.dat'; % change to your folder
fid = fopen( ffs, 'r' );
cac = textscan( fid, '%*f%s%*s%*s', 1, 'Headerlines',4, 'Delimiter','\t' );
fclose( fid );
total_x = sscanf( cac{1}{1}, '(%f %*f %*f)' );
and display the value
>> total_x
total_x =
-0.17812
In response to comment
Try this instead
%%
ffs = 'h:\m\cssm\force.dat'; % change to your folder
fid = fopen( ffs, 'r' );
cac = textscan( fid, '%*f%s%*s%*s', inf, 'Headerlines',4, 'Delimiter','\t' );
fclose( fid );
total_x = cellfun( @(chr) sscanf(chr,'(%f %*f %*f)'), cac{1} );
and check the result
>> whos total_x
Name Size Bytes Class Attributes
total_x 190978x1 1527824 double
  7 件のコメント
Moises Belda
Moises Belda 2019 年 6 月 2 日
Okay. Now it's working. Thank you very much for your help
Jan
Jan 2019 年 6 月 3 日
If it works, please select this as accepted answer.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by