Extract xy data from a structure array
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
KSSV
on 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 Comment
KSSV
on 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.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!