matlab 中 hold on 和hold off的使用(转载)

本文转载自http://blog.sina.com.cn/s/blog_7cbc9c930101082m.html



hold on 使当前轴及图形保持而不被刷新,准备接受此后将绘制的图形,多图共存

hold off 使当前轴及图形不在具备被刷新的性质,新图出现时,取消原图

hold on 在当前图的轴(坐标系)中画了一幅图,再画另一幅图时,原来的图还在,与新图共存,都看得到
close all
x=0:2:100;
y1=2*x;
y2=3*x;
y3=3.5*x;
ph1=plot(x,y1,'r-'); hold on
ph2=plot(x,y2,'g--');
ph3=plot(x,y3,'b:');
title('fake data')
xlabel('my x data');
ylabel('my y data');
th1=text(x(13),y1(13),'red line');
th2=text(x(15),y2(15),'green line');
th3=text(x(17),y3(17),'blue line');
set(th1,'Color','r');
set(th2,'Color','g');
set(th3,'Color','b')
lh=legend([ph1 ph2 ph3],{'x2';'x3';'x3.5'})


hold off 在当前图的轴(坐标系)中画了一幅图,此时,状态是hold off,则再画另一幅图时,原来的图就看不到了,在轴上绘制的是新图,原图被替换了
close all
x=0:2:100;
y1=2*x;
y2=3*x;
y3=3.5*x;
ph1=plot(x,y1,'r-'); hold off
ph2=plot(x,y2,'g--');
ph3=plot(x,y3,'b:');
title('fake data')
xlabel('my x data');
ylabel('my y data');
th1=text(x(13),y1(13),'red line');
th2=text(x(15),y2(15),'green line');
th3=text(x(17),y3(17),'blue line');
set(th1,'Color','r');
set(th2,'Color','g');
set(th3,'Color','b')
lh=legend([ph1 ph2 ph3],{'x2';'x3';'x3.5'})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值