【问题标题】:Vertical lines for Bode plots in MatlabMatlab中波特图的垂直线
【发布时间】:2017-11-15 23:16:46
【问题描述】:

我已经为我的传递函数绘制了波特图,我想知道是否有某种方法可以插入水平线或垂直线来显示增益/相位角或频率的特定值?

我发现使用以下代码可以在相位角图上画一条水平线:

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,如果这很重要。)

【问题讨论】:

    标签: matlab plot graph


    【解决方案1】:

    我不确定我是否理解你的问题,不过,我提出以下建议。

    当一个图中有多个axes时,就像波特图的情况一样,如果你想在特定的axes(或全部)中添加一些东西,你必须在调用中指定到plotaxes的句柄。

    所以,要在波德图中添加线条,您必须首先识别两个axes 中的handles:您可以这样做,至少有两种方式:

    • 使用findobj函数:ax=findobj(gcf,'type','axes')
    • 将它们提取为图中的Childrenax=get(gcf,'children')

    获得axes 中的handles 后,您可以获得它们的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])
    

    希望这会有所帮助,

    卡普拉'

    【讨论】:

    • 谢谢!我什至没有想到轴是分开的。清晰简洁;非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2011-06-09
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    • 2017-11-12
    • 1970-01-01
    • 2017-04-10
    • 1970-01-01
    相关资源
    最近更新 更多