Create legend based on a if loop statement
이전 댓글 표시
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
Jeroen van Bemmel
2022년 5월 25일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!