如何在matlab中的一个图中为多个循环添加多个图例

时间:2015-12-05 20:34:35

标签: matlab plot legend

我有一个线路网络,这些线路已经通过两个for循环添加到网络中。我已经为每个循环的线条着色,现在我需要为这两组线条添加图例。下面是我为我的网络编写的代码,在附图中显示了结果

figure('name','Distances Comparison with computed uncertainties');

labels = cellstr( num2str([1:SIFT_Length]') ); 

text(SIFT_3D(:,1), SIFT_3D(:,2),SIFT_3D(:,3), labels, 'VerticalAlignment','bottom','FontWeight','bold', 'FontSize', 18, ...
                         'HorizontalAlignment','right')

title('Accepted and Rejected Distances based on distance difference and standard deviation comparison','FontWeight','bold', 'FontSize',18);

hold on
for k = 1:length(Network_lines_Unaccepted(:,1))
 plot3([SIFT_3D(Network_lines_Unaccepted(k,1),1),SIFT_3D(Network_lines_Unaccepted(k,2),1)],...
       [SIFT_3D(Network_lines_Unaccepted(k,1),2),SIFT_3D(Network_lines_Unaccepted(k,2),2)],...
       [SIFT_3D(Network_lines_Unaccepted(k,1),3),SIFT_3D(Network_lines_Unaccepted(k,2),3)],...
       'ro--','MarkerFaceColor',[0 1 1],'MarkerEdgeColor','k', 'LineWidth',2)
end
for k = 1:length(Network_lines_accepted(:,1))
 plot3([SIFT_3D(Network_lines_accepted(k,1),1),SIFT_3D(Network_lines_accepted(k,2),1)],...
       [SIFT_3D(Network_lines_accepted(k,1),2),SIFT_3D(Network_lines_accepted(k,2),2)],...
       [SIFT_3D(Network_lines_accepted(k,1),3),SIFT_3D(Network_lines_accepted(k,2),3)],...
       'go-','MarkerFaceColor',[0 1 1],'MarkerEdgeColor','k', 'LineWidth',1.7)
end
hold off
set(gca, 'XTickLabelMode', 'manual', 'XTickLabel', []);
set(gca, 'YTickLabelMode', 'manual', 'YTickLabel', []);
set(gca, 'ZTickLabelMode', 'manual', 'ZTickLabel', []);
axis off

enter image description here

现在我想为绿线和红线添加两个图例。有人帮我说我该怎么做?

0 个答案:

没有答案