Read file txt and input value in Matlab

2 ビュー (過去 30 日間)
ly
ly 2015 年 10 月 19 日
回答済み: Star Strider 2015 年 10 月 19 日
Hi,
I want to read txt file and input value in Matlab. I use "dlmread" but it is always error:
"Error using dlmread (line 141) Mismatch between file and format string. Trouble reading number from file (row 1u, field 1u) ==> ITEM: TIMESTEP\n"
This is code:
...
clear
clc
filename = 'posi.txt';
M_initial = dlmread(filename,' ',1,0)
clear filename
...
The 'posi.txt' file was attached.
Anyone can tell what can be done in this case?
  2 件のコメント
Walter Roberson
Walter Roberson 2015 年 10 月 19 日
No file was attached.
ly
ly 2015 年 10 月 19 日
Sorry, it was attached.

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

採用された回答

Star Strider
Star Strider 2015 年 10 月 19 日
For some reason, testing for the end of file (with feof) doesn’t work with this file. A for loop and guessing at the number of ‘sections’ in the file will have to do:
fidi = fopen('posi.txt', 'rt');
for k1 = 1:20
data{k1} = textscan(fidi,'%f%f%f%f%f', 'HeaderLines',9, 'Delimiter',' ', 'CollectOutput',1);
fseek(fidi, 1, 0);
end
fclose(fidi);

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 10 月 19 日
Which MATLAB version are you using? Only quite recently has dlmread() been able to handle text anywhere in the file.
  7 件のコメント
Walter Roberson
Walter Roberson 2015 年 10 月 19 日
ly
ly 2015 年 10 月 19 日
編集済み: ly 2015 年 10 月 19 日
They are output. So I need read this txt in Matlab and analyze again.

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

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by