Create legend based on a if loop statement
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Legend finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!