Extract xy data from a structure array

1 Ansicht (letzte 30 Tage)
René
René am 8 Jun. 2021
Kommentiert: KSSV am 8 Jun. 2021
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!

Akzeptierte Antwort

KSSV
KSSV am 8 Jun. 2021
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 Kommentar
KSSV
KSSV am 8 Jun. 2021
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by