**matlab中hold on 和hold off用法**
阿新 • • 發佈:2018-12-18
1、hold on: 使當前軸及圖形保持而不被重新整理,準備接受此後將繪製的圖形,多圖共存。
2、用法說明: hold on 在當前圖的軸(座標系)中畫了一幅圖,再畫另一幅圖時,原來的圖還在,與新圖共存,都看得到
3、例子:
close all
x=0:2:100;
y1=5*x;
y2=6*x;
y3=9*x;
ph1=plot(x,y1,'r-'); hold on
ph2=plot(x,y2,'g--');
ph3=plot(x,y3,'b:');
title('三個函式影象')
xlabel('x 軸');
ylabel('y 軸');
4、hold off: 使當前軸及圖形不在具備被重新整理的性質,新圖出現時,取消原圖。
5、用法說明: hold off 在當前圖的軸(座標系)中畫了一幅圖,此時,狀態是hold off,則再畫另一幅圖時,原來的圖就看不到了,在軸上繪製的是新圖,原圖被替換了。
6、例子:
%%
close all
x=0:2:100;
y1=5*x;
y2=6*x;
y3=9*x;
ph1=plot(x,y1,'r-'); hold off
ph2=plot(x,y2,'g--');
ph3=plot(x,y3,'b:');
title('三個函式影象')
xlabel('x 軸');
ylabel('y 軸');
另:
%% close all x=0:2:100; y1=5*x; y2=6*x; y3=9*x; ph1=plot(x,y1,'r-'); hold on ph2=plot(x,y2,'g--'); ph3=plot(x,y3,'b:'); title('三個函式影象') xlabel('x 軸'); ylabel('y 軸'); 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')