필터 지우기
필터 지우기

How would you plot, run a for loop, and a string at the same time?

조회 수: 1 (최근 30일)
Erick
Erick 2012년 4월 26일
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?

답변 (1개)

Richard Brown
Richard Brown 2012년 4월 26일
change your cell format slightly
colors = {'ro', 'ko', ... etc }
then
plot(..., colors{k})
not
colors(k)
  댓글 수: 1
Jan
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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by