フィルターのクリア

reading from a text file

2 ビュー (過去 30 日間)
Jatin Arora
Jatin Arora 2012 年 9 月 25 日
hello everyone,
i am trying to read from a text file which has the following format
X: 549.123 Y: -100.235 Z: -230.89
X: 550.123 Y: -101.235 Z: -231.89
X: 551.123 Y: -102.235 Z: -232.89
X: 552.123 Y: -103.235 Z: -233.89
X: 553.123 Y: -104.235 Z: -234.89
the problem is when i read using textscan it stores the data in 3*10 cells where the first cell format is in the first column X: and in second column 549.123.
i want to store data in 3 matrices each of 1*5 ?
eagerly waiting for a reply.

採用された回答

Thomas
Thomas 2012 年 9 月 25 日
編集済み: Thomas 2012 年 9 月 25 日
Consider you have your data in file doc.txt, your ouput matrices are x_val,y_val, and z_val
fileID = fopen('doc.txt');
C = textscan(fileID, '%s %f32 %s %f32 %s %f32');
fclose(fileID);
x_val=cell2mat(C(:,2))
y_val=cell2mat(C(:,4))
z_val=cell2mat(C(:,6))
Output is
x_val =
549.12
550.12
551.12
552.12
553.12
y_val =
-100.24
-101.24
-102.24
-103.24
-104.24
z_val =
-230.89
-231.89
-232.89
-233.89
-234.89
doc.txt is as follows
X: 549.123 Y: -100.235 Z: -230.89
X: 550.123 Y: -101.235 Z: -231.89
X: 551.123 Y: -102.235 Z: -232.89
X: 552.123 Y: -103.235 Z: -233.89
X: 553.123 Y: -104.235 Z: -234.89

その他の回答 (0 件)

カテゴリ

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