How do I use multiple similar structures in a FOR loop?
Show older comments
I've been looking / studying web based documentation / artciles / blogs for 1 week but couldn't find a solution to my problem :[
I would appreciate if someone could help me with this issue.
Example of the problem:
my 1st structure (all is m1 x 1)
dmin1.Date
dmin1.Open
dmin1.High
dmin1.Low
dmin1.Close
my 2nd structure (all is m2 x 1)
dmin2.Date
etc. ...
where m1 ~= m2
the number of structures depends on some inputs, but let's assume there are just these two
What I need to do is call the appropriate structure in a for loop.
For simplicity let's assume I want to find out the length of each structure:
for i = 1 : number of structures (in my example 2)
dates_length(i) = length(dmin"i".Date); % **
% -----------------------
% some code for execution
% -----------------------
end
** for the statement //dmin"i".Date// I need your help - don't know how to correctly write it so matlab will do what I want.
So after the for cycle ends, when I type dates_length in the command window the result should be:
dates_length =
m1 m2
Hope I've explained my issue clearly enough. I'll appreciate any feedback which helps to solve this issue, also the one that might opose the technique I use for sampling the data ... (I've also read the FAQ that such a creation of variables / structures is not recommended, but I can't figure out any other way how to sample the data)
1 Comment
Todd Flanagan
on 20 Jan 2011
Michal, I edited your question for clarity. Feel free to update it if you don't think I captured your real question.
Accepted Answer
More Answers (1)
Doug Hull
on 20 Jan 2011
1 vote
See this similar question for an extensive answer.
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!