matlab 中 hold on 和hold off的使用


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'})
matlab <wbr>中 <wbr>hold <wbr>on <wbr>和hold <wbr>off的使用

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'})
matlab <wbr>中 <wbr>hold <wbr>on <wbr>和hold <wbr>off的使用

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM