Neilton:
It sounds like you want to call plot on several variables (your table names), and those names vary in a systematic way. You can do this with the eval function, but this isn't generally a recommended approach. There's some detail about why not here. The code that would do this might look something like: eval(['plot(Freq' num2str(c) '.tempo, Freq' num2str(c) '.Z)'])
You can think of the eval strategy as creating a character vector and then parsing that as if it were code in your script.
If you're in control of the code that makes these variables, you might consider putting all of those tables in a cell array. That makes it much easier to iterate (for plot, but also for anything else).
a={table(rand(10,1)) table(rand(10,1)) table(rand(10,1))};
for i = 1:numel(a)
plot(a{i}.Var1)
hold on
end
Perhaps even better is thinking about a data structure that allows all frequencies in one table. Though it's hard to guess without knowing what that might be, perhaps Freq would do well as a column in your table rather than a table for each Freq? Just a thought!
2 Comments
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/632489-how-to-use-for-loop-to-plot-multiple-graphs#comment_1100754
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/632489-how-to-use-for-loop-to-plot-multiple-graphs#comment_1100754
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/632489-how-to-use-for-loop-to-plot-multiple-graphs#comment_1100764
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/632489-how-to-use-for-loop-to-plot-multiple-graphs#comment_1100764
Sign in to comment.