How to insert legend in plot after a for cycle?
이전 댓글 표시
I have a problem with the insertion of legend in a 3D plot in matlab. I have a list of data, in particular I have a nx3 matrix filled with data to plot and I want to separate these data by means of a discriminant. In my case the discriminant is time, so if i-th data is before the discriminant time it will be plotted in blue color, otherwise in red color. The code is
figure(1)
plot3(ra(1),dec(1),Time2plot(1),'*','Color','r', 'DisplayName', 'observation day');
hold on;
plot3(ra(end),dec(end),Time2plot(end),'*','Color','b','DisplayName', 'next day');
legend show;
for i = 1:length(Time2plot)
if timeofday(Time2plot(i)) > B(1) && timeofday(Time2plot(i)) < B(2)
hold on;
plot3(ra(i),dec(i),Time2plot(i),'*','Color', 'b');
else
hold on;
plot3(ra(i),dec(i),Time2plot(i),'*','Color','r');
end
end
hold on;
title(['RA Dec in 3D ', date(1,1)]);
xlabel('RA');
ylabel('Dec');
zlabel('Time');
ztickformat('HH:mm:ss');
grid on;
where B is discriminant time.
The result is

The issue is that I'd like only two line in legend: 'next day' and 'observation day' and not all data. Someone can help me?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
