how to extract data from structure efficiently

2 ビュー (過去 30 日間)
Micke Malmström
Micke Malmström 2016 年 4 月 13 日
コメント済み: MnM 2016 年 4 月 16 日
Hi
I have this structure with sometimes allot of A_scans:
>> Data.CH1
ans =
name: 'CH1'
Props: [1x1 struct]
A_scan1_1: [1x1 struct]
A_scan1_2: [1x1 struct]
A_scan1_3: [1x1 struct]
A_scan1_4: [1x1 struct]
A_scan1_5: [1x1 struct]
...
Where ecach scans has a "data" variable, that I want to put in a matrix row by row:
Data.CH1.A_scan1_1
ans =
name: 'A_scan1_1'
Props: [1x1 struct]
data: [1x31990 int16]
What is the most efficient way of extracting the "data" arrays into a matrix? I guess i could do a forloop but I have a feeling there might be a faster way?
  2 件のコメント
Stephen23
Stephen23 2016 年 4 月 13 日
編集済み: Stephen23 2016 年 4 月 13 日
It really depends on what you are doing:
  • if you are generating the structure Data, then you should follow Walter Roberson's suggestion and use a non-scalar structure to store the data. This would be the optimal solution, and it would be trivial to access the data inside the structure.
  • if Data is being provided to you then unfortunately this not a very convenient format to process without loops: even if it could be possible without a loop, a loop may well be the clearest code.
MnM
MnM 2016 年 4 月 16 日
the data comes from a tdms file.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 4 月 13 日
The more efficient way to extract it efficiently is to use a single A_scan1 that is indexed -- a struct array. Then you could do something like horzcat(A_scan1.data)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by