matlab hleg,[转载]matlab绘图,句柄设置legend

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

函数绘制的图形如下:

a4c26d1e5885305701be709a3d33442f.png

[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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值