matlab 如何创建多个legend

代码如下:

x = -pi:pi/20:pi;
p1=plot(x,cos(x),'-ro');
hold on
p2=plot(x,sin(x),'-.b')
[legh,objh,outh,outm]=legend('cos(x)');
legh2=copyobj(legh,gcf);
[legh2,objh2]=legend(p2,'sin(x)',2);


也可以这样:


x = -pi:pi/20:pi;
p1=plot(x,cos(x),'-ro');
hold on
p2=plot(x,sin(x),'-.b')
h1=legend('cos(x)');
copyobj(h1,gcf);
legend(p2,'sin(x)',2);

你可能感兴趣的:(Matlab)