Import data with textscan that is non-periodic

1 回表示 (過去 30 日間)
Luca Amerio
Luca Amerio 2013 年 2 月 28 日
Hi,
I need to import some datas from a file that is structured as follow:
Time1 (X11 Y11 Z11) (X12 Y12 Z12) ... (X1n Y1n Z1n)
Time2 (X21 Y21 Z21) (X22 Y22 Z22) ... (X2n Y2n Z2n)
...
Time_m (Xm1 Ym1 Zm1) (Xm2 Ym2 Zm2) ... (Xmn Ymn Zmn)
I would like to obtain a Time vector and 3 matrix X Y Z.
I've tried with textscan but the Time at the beginning gives me some problems: if I use as formatSpec '%f (%f %f %f)' it only reads the first 4 numbers, on the other hand if I use '(%f %f %f)' it does read anything.
I've managed to solve this in an horrible way:
formatSpec=('%f');
for i=1:nprobes
formatSpec=strcat(formatSpec,' (%f %f %f) ');
end
data=textscan(FileID,formatSpec,'HeaderLines',4);
This way I create a 3*N + 1 cell array that i need to merge as:
X=[data{2},data{5},data{8}...data{3N-1}];
Y=[data{3},data{6},data{9}...data{3N}]
Z=[data{4},data{7},data{10}...data{3N+1}]
but i don't know how to do it (since N is very big)...
Can you please help?
Thanks
  4 件のコメント
Cedric
Cedric 2013 年 3 月 21 日
If we answered your question, please chose one answer as the answer (and/or vote for people who contributed).
Luca Amerio
Luca Amerio 2013 年 3 月 22 日
Thank you so much. I'll try with the method you told me.
Bye!

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

採用された回答

Walter Roberson
Walter Roberson 2013 年 2 月 28 日
編集済み: Walter Roberson 2013 年 2 月 28 日
formatSpec = ['%f', repmat('(%f %f %f)', 1, nprobes) ]
or, use repmat('%f', 1, nprobes*3+1) as the format and use ' ()' as the Delimiter with MultipleDelimsAsOne set true.

その他の回答 (1 件)

Cedric
Cedric 2013 年 2 月 28 日
編集済み: Cedric 2013 年 2 月 28 日
Just for the merge, without talking about improving the overall approach, you can do
X = [data{2:3:3*N-1}] ;
Y = [data{3:3:3*N}] ;
Z = [data{4:3:3*N+1}] ;

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by