How would you plot, run a for loop, and a string at the same time?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Richard Brown
2012-4-26
change your cell format slightly
colors = {'ro', 'ko', ... etc }
then
plot(..., colors{k})
not
colors(k)
1 个评论
Jan
2012-4-26
"[{'ro'},{'ko'},{'bo'},{'mo'},{'go'}]" and "{'ro','ko','bo','mo','go'}" are equivalent, but the later is nicer and faster.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!