Extract xy data from a structure array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
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
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!