clear
clc
t=0:pi/48:2*pi;
y1=sin(t);
y2=cos(t);
y3=y1.*y2;
y4=0.5*(y1+y2);
hold on
h1=plot(t,y1,'r-')
h11 =
plot(t(1:10:end),y1(1:10:end),'*','MarkerFaceColor','r','MarkerEdgeColor','r');
h2=plot(t,y2,'b-');
h22 =
plot(t(1:10:end),y2(1:10:end),'.','MarkerFaceColor','b','MarkerEdgeColor','b');
h3=plot(t,y3,'y');
h4=plot(t,y4,'g');
hold off
[legh,objh,outh,outm]=legend([h1,h2],'y1','y2',1);
legend boxoff
% matlab7
set(objh(4),'marker','*');
set(objh(6),'marker','.');
legh2=copyobj(legh,gcf);
[legh2,objh2]=legend([h3,h4],'y3','y4',2);
legend boxoff
函数绘制的图形如下:
[legh,objh,outh,outm]=legend([h1,h2],'y1','y2',1);
legend boxoff
% matlab7
set(objh(4),'marker','*');
set(objh(6),'marker','.');
legh2=copyobj(legh,gcf);
[legh2,objh2]=legend([h3,h4],'y3','y4',2);
legend boxoff
作用是添加legend,并设置marker的相应格式。set(objh(end),'marker','*')作用是:在legend中,给最后一个线形添加一个marker作为标识,set(objh(end-1),'marker','*'),给最后一个线形添加两个个marker作为标识;set(objh(end-2),'marker','*')作用是:在legend中,给最后一个线形添加一个marker作为标识,set(objh(end-3),'marker','*'),给最后一个线形添加两个个marker作为标识……
legh2=copyobj(legh,gcf); 作用是拷贝当前图的legh给legh2.