How would you plot, run a for loop, and a string at the same time?
1 view (last 30 days)
Show older comments
Right now, I'm trying to plot 5 sets of data in 3 groups without having to retype the plots 15 times. Basically, I'm just trying to save lines of code. However, I also want to distinguish the 5 sets of data in each 3 groups by separating them by color and dots. This is what I have so far:
colors=[{'ro'},{'ko'},{'bo'},{'mo'},{'go'}];
figure(1) %p/patm vs x
for k=1:5
hold on
plot(L(1),pt_patm(6,k))
plot(L(2:6),p_patm(1:5,k),colors(k))
end
L is a 1x6 Matrix; p_patm is a 5x5 matrix. I want the colors to change with each iteration. Instead, I'm getting an error that says
??? Error using ==> plot Conversion to double from cell is not possible.
Error in ==> fanno at 47 plot(L(2:6),p_patm(1:5,k),colors(k))
I get that this doesn't work with cell matrices. However, if I remove the '{}' brackets, colors turns into a 1x10) matrix which doesn't line up with the code that I have. Does anyone see a better way that changes 'ro' to 'ko' to (insert color/shape here)each time the code pulls out a different set of data?
0 Comments
Answers (1)
Richard Brown
on 26 Apr 2012
change your cell format slightly
colors = {'ro', 'ko', ... etc }
then
plot(..., colors{k})
not
colors(k)
1 Comment
Jan
on 26 Apr 2012
"[{'ro'},{'ko'},{'bo'},{'mo'},{'go'}]" and "{'ro','ko','bo','mo','go'}" are equivalent, but the later is nicer and faster.
See Also
Categories
Find more on Annotations 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!