Extract xy data from a structure array

1 回表示 (過去 30 日間)
René
René 2021 年 6 月 8 日
コメント済み: KSSV 2021 年 6 月 8 日
I have imported a lot of xy data into a structure array. Inside the struct the last column include in each cell the xy table of one sample. How do I extract the data in a single matrix? The Matrix should have two column per sample (sample A column 1,2; sample B column 3,4...etc).
I tried a loop like this to start with:
for k = 1:numel(S)
A(k) = table2array(S(k).data)
end
After this I wanted to try an additional loop to integrate all matrices in a single matrix
The error says: Unable to perform assigment because the left and right sides have a different number of elements.
Thank you for your help!

採用された回答

KSSV
KSSV 2021 年 6 月 8 日
You have to do a proper initialization.
If you are not aware of dimensions or if dimensions change in loop; go for cell array.
A = cell(numel(S),1) ;
for k = 1:numel(S)
A{k} = table2array(S(k).data)
end
You can access A using A{1}, A{2} ..A{end} etc.
If you think the dimensions do not chnage in loop and it is a matrix.
A = zeros([],[].numel(S)) ;
for k = 1:numel(S)
A(:,:,k) = table2array(S(k).data)
end
  1 件のコメント
KSSV
KSSV 2021 年 6 月 8 日
Rene commented:
Wow, thank you very much!
The tip with A{1} was also very helpful! I added
B = [A{1:numel(S)}] and got the final matrix.

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by