2017-03-31 123 views
0

我繪製了一個傳遞函數的波特圖,我想知道是否有某種方法可以插入水平線或垂直線來顯示增益/相位角或頻率的特定值?Matlab中波特圖的垂直線

我已經用下面的代碼,我可以借鑑的相位角圖上的水平線發現:

x = linspace(10^-1,10^2,100); 

for bleh = 1:length(x) 
     y(bleh) = -30.9638; 
end 

bode(num, den) 
hold on 
plot(x,y) 

但是,這似乎並沒有在增益曲線申請,也沒有我的知識有限(只有對我有意義的方式)垂直線。我試過了:

y1 = get(gca,'ylim'); 
w1 = 1.2; 

bode(num, den) 
hold on 

plot(x,y,[w1 w1],y1) 

但是我只得到一個水平線,就像從上面的代碼中完成的一樣。 這是一種可能性嗎?

(使用R2017a,如果該事項。)

回答

2

我不知道我理解你的問題,不過,我提出以下建議。

當有更多的一個在圖axes,因爲它是波德圖的情況下,如果你想在添加一些特定axes(或全部)你必須指定,在調用plotaxes的句柄。

因此,增加線路中的波特圖,你必須先確定的handles兩個axes:你可以做到這一點,至少有兩個方法:使用

  • findobj功能:ax=findobj(gcf,'type','axes')
  • 提取它們的身影Childrenax=get(gcf,'children')

一旦你有axeshandles,你CA n獲得他們的XLimYLim,您可以使用它來限制要添加的行的範圍。

在下面的例子中,我使用了上面提出的方法在每個圖中添加兩行。

水平線和垂直線被添加到X軸和Y軸的中點(可能這點沒有相關的含義,但它只是一個例子)。

% Define a transfer function 
H = tf([1 0.1 7.5],[1 0.12 9 0 0]); 
% PLot the bode diagram 
bode(H) 
% Get the handles of the axes 
ax=findobj(gcf,'type','axes') 
phase_ax=ax(1) 
mag_ax=ax(2) 
% Get the X axis limits (it is the same for both the plot 
ax_xlim=phase_ax.XLim 
% Get the Y axis limits 
phase_ylim=phase_ax.YLim 
mag_ylim=mag_ax.YLim 
% 
% Define some points to be used in the plot 
% middle point of the X and Y axes of the two plots 
% 
mid_x=(ax_xlim(1)+ax_xlim(2))/2 
mid_phase_y=(phase_ylim(1)+phase_ylim(2))/2 
mid_mag_y=(mag_ylim(1)+mag_ylim(2))/2 
% Set hold to on to add the line 
hold(phase_ax,'on') 
% Add a vertical line in the Phase plot 
plot(phase_ax,[mid_x mid_x],[phase_ylim(1) phase_ylim(2)]) 
% Add an horizontal line in the Phase plot 
plot(phase_ax,[ax_xlim(1), ax_xlim(2)],[mid_phase_y mid_phase_y]) 
% Set hold to on to add the line 
hold(mag_ax,'on') 
% Add a vertical line in the Magnitide plot 
plot(mag_ax,[mid_x mid_x],[mag_ylim(1) mag_ylim(2)]) 
% Add an Horizontal line in the Magnitide plot 
plot(mag_ax,[ax_xlim(1), ax_xlim(2)],[mid_mag_y mid_mag_y]) 

enter image description here

希望這有助於

Qapla」

+0

謝謝!我甚至沒有想到這些軸是分開的。清晰簡潔;非常感激! – Asinine

+0

不客氣!快樂我一直在使用你。 –