【问题标题】:How do I reach first and second plots from bode()如何从 bode() 到达第一个和第二个图
【发布时间】:2017-05-18 04:04:48
【问题描述】:

我知道如何使用 bode() 函数创建波特图。如果我想重叠两个或更多系统频率响应,我使用

bode(sys1,sys2,...)

hold on

例如,当我想到达情节以便用 text() 放置图例时,很容易到达第二个情节。像图形指针这样的东西总是返回到第二个图(相位图)。

即,如果尝试这些行:

G = tf([1],[1 6]); figure(1); bode(G); text(10,-20,'text');
G = tf([1],[1 6]); figure(2); bode(G); text(10,-20,'text');

当我回到第一个图时,用图(1),然后尝试

figure(1); text(10,-20,'text')

图例显示在第二个图中(相位图)

我尝试这些其他行:

P = bodeoptions; % Set phase visiblity to off
P.PhaseVisible = 'off';
G = tf([1],[1 6]);
figure(1); bode(G,P); text(10,-20,'text');
figure(1); text(10,-20,'text');

如您所见,即使我关闭相位图可见性,图例也不会显示。

本质上,我的问题是,我如何逐个到达第一个和第二个情节?我尝试使用 subplot(),但很明显这不是 Matlab 跟踪这些图的方式。

提前致谢。

【问题讨论】:

  • 如果你有两个不同的图形,你可以在命令窗口中输入图形的指针为figure(figure number)
  • 似乎 bode() 和 bodeplot() 将 de Bode 的图作为一个单元进行跟踪。如果我使用数字图,Matlab 总是将此图形单元指向第二个(最后一个对象)图。

标签: matlab


【解决方案1】:

这一切都进入了上面的情节,因为在bodeplot 命令之后,下面的情节是活跃的。直觉上有人会想调用subplot(2,1,1),但这只会在 if 之上创建新的空白图。因此我们应该这样做:

% First, define arbitrary transfer function G(s), domain ww 
% and function we want to plot on magnitude plot.
s = tf('s');
G = 50 / ( s*(1.6*s+1)*(0.23*s+1) );
ww = logspace(0,3,5000);
y = 10.^(-2*log10(ww)+log10(150));
hand = figure;                   % create a handle to new figure
h = bodeplot(G,ww);
hold on;
children = get(hand, 'Children') % use this handle to obtain list of figure's children

% We see that children has 3 objects:
% 1) Context Menu 2) Axis object to Phase Plot 3) Axis object to Magnitude Plot

magChild = children(3);          % Pick a handle to axes of magnitude in bode diagram.
% magChild = childern(2)         % This way you can add data to Phase Plot.
axes(magChild)                   % Make those axes current
loglog(ww,y,'r');
legend('transfer function','added curve')

【讨论】:

    【解决方案2】:

    您可以使用以下方法分别获取每个系统的幅度和相位数据:

    [mag,phase] = bode(sys,w) 
    

    现在您可以使用subplotplot 来绘制您想要的图表。

    【讨论】:

    • 用 figure(),Matlab 指向第二个图(相位)。即 G=tf([1],[1 6]);figure(1);bode(G);text(10,-2​​0,'text') G=tf([1],[1 6]); figure(2);bode(G);text(10,-2​​0,'text') 如何到达 Mag 图以便在 (10,-2​​0) 中找到图例“text”?
    • 我编辑了原始答案,您可以使用mag 使用普通绘图并做任何您想做的事情。
    【解决方案3】:

    我能够执行的唯一解决方案是考虑轴位置。它不是很干净,但它可以工作。 这是选择磁图的代码:

    ejes=findobj(get(gcf,'children'),'Type','axes','visible','on');
    posicion=get(ejes,'pos');
    tam=length(posicion);
    for ii=1:tam
    a=posicion{ii}(2);
    vectorPos(ii)=a;
    end
    [valorMax,ind]=max(vectorPos); % min for choosing the phase plot
    axes(ejes(ind)) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-24
      • 1970-01-01
      • 1970-01-01
      • 2020-11-18
      • 1970-01-01
      相关资源
      最近更新 更多