我想要绘制一些数据如下:Matlab的只显示在传说中的某些元素
figure(2);
l = plot(1:50,data_a(:,2),1:50, data_a(:,2), 'b*');
set(l,'Color','red');
hold on;
lb = plot(1:50,data_b(:,2),1:50, data_b(:,2), 'b*');
set(lb, 'Color', 'blue');
hold on;
lc = plot(1:50,data_c(:,2),1:50, data_c(:,2), 'b*');
set(lc, 'Color', 'green');
hold on;
ld = plot(1:50,data_d(:,2),1:50, data_d(:,2), 'b*');
set(ld, 'Color', 'cyan');
legend([l,lb,lc,ld], 'A', 'B', 'C', 'D');
如果我只是用
legend('show')
这也将包括文字绘制的点()功能,我不想要。因此,为什么在最后一行我指定我只想要元素l,lb,lc和ld(图)被包含在图例中。
这与指令given on the MathWorks site一致。
但是,它返回一个错误:
Error using legend (line 120)
Operands to the || and && operators must be convertible to logical scalar values.
Error in visualizer (line 33)
legend([l,lb,lc,ld], 'A', 'B', 'C', 'D');
有什么建议?
你的手柄是不是标量。每次调用“plot”时,你都在绘制两件事情。 – horchler