Legend showing same symbol for loop plot

2 visualizaciones (últimos 30 días)
Cutie
Cutie el 29 de Abr. de 2023
Editada: Cutie el 29 de Abr. de 2023
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

Respuesta aceptada

Adam Danz
Adam Danz el 29 de Abr. de 2023
Editada: Adam Danz el 29 de Abr. de 2023
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 comentario
Cutie
Cutie el 29 de Abr. de 2023
Editada: Cutie el 29 de Abr. de 2023
I works, thanks.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Genomics and Next Generation Sequencing en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by