Create legend based on a if loop statement
Mostrar comentarios más antiguos
I have a for-loop and if-loop making a scatter plot, where a 3D coordinate is plotted with one of three possible colors based on the if loop condition. so the coordinate becomes either green, red or black. I want to make a legend denoting these three conditions, but my current code denotes three green dots instead of the three different colors.
Anybody knows how to fix this problem?
Thanks in advance
figure(1)
for j=1:16
for i=(1+((j-1)*61)):(30+((j-1)*61)) % inputting command (only gets desired nodes from data file)
if CPN_1(i) < -1 && CPN_1(i) > -2 % pressure between -2 and -1:color red
scatter3(x_1(i),y_1(i),z_1(i),200,'filled','red')
hold on
elseif CPN_1(i) < -2
scatter3(x_1(i),y_1(i),z_1(i),250,'filled','black') % pressure below -2, color black
hold on
else
scatter3(x_1(i),y_1(i),z_1(i),100,'s','filled','green') % pressure higher then -1, color green
hold on
end
end
end
xlabel('x [mm]')
ylabel('y [mm]')
zlabel('z [mm]')
title('Pressure distribution suction side')
legend('-C_{PN} > 2', '2> -C_{PN} > 1','-C_{PN} < 1') % current wrong legend command
hold off
1 comentario
Jeroen van Bemmel
el 25 de Mayo de 2022
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Legend en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!