필터 지우기
필터 지우기

Legend showing same symbol for loop plot

조회 수: 1 (최근 30일)
Cutie
Cutie 2023년 4월 29일
편집: Cutie 2023년 4월 29일
My legend is showing the same symbol for different data. My code is as follows
for i=1:size(obs,1)
x = V(:,1)'*obs(i,:)';
y = V(:,2)'*obs(i,:)';
z = V(:,3)'*obs(i,:)';
if(grp{i}=='Cancer')
plot3(x,y,z,'r+','LineWidth',2);
else
plot3(x,y,z,'ko','LineWidth',2);
end
end
Unrecognized function or variable 'obs'.
xlabel ('V1 modes')
ylabel ('V2 modes')
zlabel ('V3 modes')
legend('Cancer Patients', 'Normal Patients')
In the output, the legend is showins the 'r+' for both cancer patients and normal patients

채택된 답변

Adam Danz
Adam Danz 2023년 4월 29일
편집: Adam Danz 2023년 4월 29일
Try this
for i=1:size(obs,1)
x = V(:,1)'*obs(i,:)';
y = V(:,2)'*obs(i,:)';
z = V(:,3)'*obs(i,:)';
if(grp{i}=='Cancer')
hc = plot3(x,y,z,'r+','LineWidth',2,'DisplayName','Cancer');
else
hn = plot3(x,y,z,'ko','LineWidth',2,'DisplayName', 'Normal');
end
end
legend([hc,hn])
If you still only see the Cancer group in the legend, check that grp contains character vectors that aren't 'Cancer'.
  댓글 수: 1
Cutie
Cutie 2023년 4월 29일
편집: Cutie 2023년 4월 29일
I works, thanks.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by