Matlab中Bode图的垂直线
我已经为我的传递函数绘制了一个Bode图,我想知道是否有办法插入水平线或垂直线来显示增益/相位角或频率的特定值 我发现通过以下代码,我可以在相位角图上画一条水平线:Matlab中Bode图的垂直线,matlab,plot,graph,Matlab,Plot,Graph,我已经为我的传递函数绘制了一个Bode图,我想知道是否有办法插入水平线或垂直线来显示增益/相位角或频率的特定值 我发现通过以下代码,我可以在相位角图上画一条水平线: 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
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,如果有必要的话。)我不确定我是否理解您的问题,不过,我提出以下建议 当一个图形中有多个
轴时,就像bode图的情况一样,如果要在特定轴(或全部)中添加某些内容,则必须在调用绘图时指定轴的句柄
因此,要在bode图中添加线条,首先必须识别两个轴的句柄:至少可以通过两种方式完成:
- 使用
findobj
函数:ax=findobj(gcf,'type','axes')
- 将它们提取为图的
Children
:ax=get(gcf,'Children')
一旦有了轴的句柄
,就可以获得它们的XLim
和YLim
,可以使用它们来限制要添加的行的范围
在下面的示例中,我使用了上面提出的方法在每个图中添加两条线
横线和竖线在X和Y轴的中间点加上(这一点不具有相关的意义,但它只是……一个例子)。
希望这有帮助
Qapla’我不确定我是否理解您的问题,不过,我提出以下建议
当一个图形中有多个轴时,就像bode图的情况一样,如果要在特定轴(或全部)中添加某些内容,则必须在调用绘图时指定轴的句柄
因此,要在bode图中添加线条,首先必须识别两个轴的句柄:至少可以通过两种方式完成:
- 使用
findobj
函数:ax=findobj(gcf,'type','axes')
- 将它们提取为图的
Children
:ax=get(gcf,'Children')
一旦有了轴的句柄
,就可以获得它们的XLim
和YLim
,可以使用它们来限制要添加的行的范围
在下面的示例中,我使用了上面提出的方法在每个图中添加两条线
横线和竖线在X和Y轴的中间点加上(这一点不具有相关的意义,但它只是……一个例子)。
希望这有帮助
Qapla’谢谢!我甚至没有想到斧头是分开的。简洁明了;非常感谢!非常感谢。我甚至没有想到斧头是分开的。简洁明了;非常感谢!
% 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])