Extract xy data from a structure array
1 回表示 (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
採用された回答
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
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 Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!