How to read a term of the file

2 ビュー (過去 30 日間)
Moises Belda
Moises Belda 2019 年 6 月 19 日
編集済み: Jan 2019 年 6 月 19 日
Hi, I would know if someone can help me with this. In the file I have, I only need to read the third term of the second column, I mean, the total_z colum, which in the first row is -9.471316e-01. So I need to obtain this term of all the file.
Thanks
  2 件のコメント
Bob Thompson
Bob Thompson 2019 年 6 月 19 日
編集済み: Bob Thompson 2019 年 6 月 19 日
I do not have the ability to look at your data. Would you describe the file layout as a numeric data sheet? If so, the simplest way to accomplish what you are asking for is to read the entire file into a matrix, and then extract that one value by indexing.
Moises Belda
Moises Belda 2019 年 6 月 19 日
編集済み: Jan 2019 年 6 月 19 日
I have something like that, which allows me to read the first term of this column, but I need to read the third term. I know I have to change something, but I quite confused with the %f and %s.
%%
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} );

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

採用された回答

infinity
infinity 2019 年 6 月 19 日
Hello,
Here is a solution that you can refer:
clear
format long
a = readtable('force1.dat','HeaderLines',4);
b = a(:,4);
c = b{:,1};
n = length(c);
d = zeros(n,1);
for i = 1:n
d(i) = str2double(c{i}(1:end-1));
end
d(1)
Your data is now saved in varibale d.
Best rergards,
Trung
  5 件のコメント
Bob Thompson
Bob Thompson 2019 年 6 月 19 日
Have you tried Trung's answer?
Moises Belda
Moises Belda 2019 年 6 月 19 日
Not yet, until tomorrow I won’t check it.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by