2014-11-25 116 views
0

我有两个5 + 20的数组,我想在一个图中显示。如果我添加使用insert legend按钮,我得到40个条目的传说传说Matlab:两个图的组图例条目

figure; 
hold on; 
h1 = plot(hamming_intra, 'bo'); 
h2 = plot(hamming_inter, 'r+'); 
hold off; 

:但是,传说应该只由两个条目,每个单个条目指显示曲线图的一个。我的目标是获得一个带有两个条目的传说(一个带有红十字和一个带蓝点)。

enter image description here

的阵列hamming_intrahamming_inter由双值:

>> whos hamming_inter 
Name    Size   Bytes Class  Attributes 

hamming_inter  5x20    800 double    

回答

0

我发现了MathWorks的论坛解决方案:

figure; 
hold on; 
h1 = plot(hamming_intra, 'bo'); 
h2 = plot(hamming_inter, 'r+'); 
hold off; 
h = get(gca,'Children'); 
v = [h(1) h(21)]'; %in my case the first and the 21st entry correspond the the first entry of both plots 
legend(v, 'data1', 'data2'); 
0
figure; 
h1 = plot(hamming_intra, 'bo'); 
hold on 
h2 = plot(hamming_inter, 'r+'); 
legend([h1, h2],'hamming_intra','hamming_inter') 
+0

不会永远工作,尝试用rand(2,10)替换集合,它将失败。这取决于你的设置的格式。 – 2014-11-25 09:36:04

+0

我已经试过这个,但它给出了一个错误: ||的操作数。和&&操作符必须可以转换为逻辑标量值。 图例中的错误(行194) elseif narg> 0 &&〜ischar(varargin {1})&& ... – 2014-11-25 10:12:20