2017-03-31 177 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

不客气!快乐我一直在使用你。 –