The colors displayed in the legend do not match the plot colors.

조회 수: 3 (최근 30일)
Priya
Priya 2014년 6월 23일
편집: Mischa Kim 2014년 6월 23일
This is my code,
colors = ['r';'m';'b';'g';'c'];
symbols = ['*-';'+-';'*-';'+-';'*-'];
for k1 = 1:5
colsym = [colors(k1),symbols(k1,1:2)];
plot(x, y, colsym)
hold on
end
legend('-0.02','-0.01','0','0.01','0.02')
Thanks in advance.

답변 (1개)

Mischa Kim
Mischa Kim 2014년 6월 23일
편집: Mischa Kim 2014년 6월 23일
Hello Priya, not sure how you have defined your y, so check out the code below:
xCenter = 0;
yCenter = 0;
theta = 0 : 0.01 : 2*pi;
colors = ['r';'m';'b';'g';'c'];
symbols = ['*-';'+-';'*-';'+-';'*-'];
for k1 = 1:5
xRadius = k1;
yRadius = 5/k1;
x = xRadius * cos(theta) + xCenter;
y = yRadius * sin(theta) + yCenter;
colsym = [colors(k1),symbols(k1,1:2)];
plot(x, y, colsym)
hold on
end
legend('-0.02','-0.01','0','0.01','0.02')
  댓글 수: 3
Priya
Priya 2014년 6월 23일
편집: Priya 2014년 6월 23일
I get this,
Index exceeds matrix dimensions.
Error in test_contact_ellipse (line 232) plot(x, y(k1,:), colsym)
Actually, in the link , I have made some changes to my code which is nothing but placing my entire code into a for loop.
Mischa Kim
Mischa Kim 2014년 6월 23일
편집: Mischa Kim 2014년 6월 23일
See updated code above. The four lines succeeding the for command need to/can be adapted/moved.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by