How to loop over different named structs?
Show older comments
Hi All,
I have a set of cursor_info's which containt the x,y- coordinates generated from different figures, as such:
cursor_info 1x1 struct
cursor_info1 1x1 struct
cursor_info2 1x1 struct
cursor_info3 1x1 struct
.
.
cursor_infoN 1x1 struct
By using a for loop and the cell2mat funtction i'm trying to get all cursor info in matrix form, like this
for i = 1:N
All_data(i,:) = cell2mat({cursor_info{I}.Position}');
end
But I don't know how to change the cursor_info's name in the for loop from cursor_info to cursor_info1 and so on.
Thanks in advace!
2 Comments
Stephen23
on 20 May 2021
@Aris van Houten: you forgot to tell us the most important piece of information: how did you get all of those individual variables into the workspace? Did you name them all by hand? Did you load them from a mat file (or files)? Were they created by a badly-written script?
Aris van Houten
on 20 May 2021
Accepted Answer
More Answers (1)
Sulaymon Eshkabilov
on 20 May 2021
for ii = 1:N
All_data(ii,:) = cell2mat({['cursor_info' num2str(ii)].Position}');
end
Good luck
1 Comment
Aris van Houten
on 20 May 2021
Categories
Find more on MATLAB Support for MinGW-w64 C/C++ Compiler 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!