首页 文章

在MATLAB中用许多图改变波特图的样式

提问于
浏览
0

我在MATLAB中使用以下脚本生成具有许多bodeplot函数的图:

function bodetest()
  bodesample = tf([3, -2, 1], [4, -5, 5, 6, 3]);
  bodesample2 = tf([1, -1, 1], [4, 7, 5, 6, 3]);
  h = bodeplot([bodesample, bodesample; bodesample, bodesample],[bodesample2, bodesample2; bodesample2, bodesample2]);
end

enter image description here

现在我将句柄存储在 h 变量中 . 如何使用处理程序以编程方式更改每个单独的绘图的线条颜色和样式?

例如,我想将位置(1,2)中的绿色相位图从绿色更改为红色,将位置(2,1)中的图形的蓝色大小更改为黑色 .

2 回答

  • 1

    使用传统的使用图形手柄的方式似乎更方便 .

    %Making desired bodeplots
    fh=figure;    %Figure handle
    bodeplot([bodesample, bodesample; bodesample, bodesample], ...   %Bodeplot for System-1 
        [bodesample2, bodesample2; bodesample2, bodesample2]);       %Bodeplot for System-2
    

    bodeplots的子项以相反的顺序编号,即 fh.Children 按以下顺序排列:

    image1

    图.fh.Children的顺序,1是ContextMenu

    此时忽略上图中的线条颜色(稍后将讨论) .

    然后更进一步, fh.Children 的孩子被命令使 1 成为第一个系统, 2 是第二个系统,依此类推 .

    线条的颜色属性实际上是上述子元素的属性 .


    例子

    For MATLAB R2014a and earlier versions (also applicable on the later versions):

    看看你的bodeplot的color of lines,似乎你正在使用MATLAB R2014a或更早版本,所以你必须使用getset .

    • 要将第1行和第2列中的绿色相位图更改为红色,请使用:
    ch=get(fh,'children');  ch=get(ch(5),'children');  ch=get(ch(2),'children'); 
    % '5' according to the map shown before. And '2' since it is the second system
    set(ch,'color','r');
    
    • 类似地将第4行和第1列中的蓝色幅度图更改为黑色,使用:
    ch=get(fh,'children');  ch=get(ch(6),'children');  ch=get(ch(1),'children');
    % '6' according to the map shown before. And '1' since it is the first system 
    set(ch,'color','k');
    

    For MATLAB R2014b and later versions:

    • 要将第1行和第2列中的绿色(在R2014b及更高版本中为橙色)相位图更改为红色,请使用:
    fh.Children(5).Children(2).Children.Color = 'r';     
    % '5' according to the map shown before. And '2' since it is the second system
    
    • 类似地将第4行和第1列中的蓝色幅度图更改为黑色,使用:
    fh.Children(6).Children(1).Children.Color = 'k';
    % '6' according to the map shown before. And '1' since it is the first system
    

    documentation中查看颜色的短/长名称及其RGB三元组,或使用其RGB值指定自己的颜色 . 其他行属性(如 LineStyleLineWidthMarkerSize 等)也可以以类似的方式更改 .

    也可以使用getoptions和setoptions使用bodeplot句柄 .

  • 0

    您可以从绘图中提取线条手柄并通过更改单个颜色

    linehandle = findobj(gcf, 'Type','line');
     set(linehandle(ii), 'Color', [1 1 0]);
    

    问题是将一条线映射到一个特定的图(搜索查询找到24行) .

    分析相应轴的位置可能会有所帮助 . 例如

    linehandle(9).Parent.Parent
    

    提供

    Axes with properties:
    
               XLim: [0.0100 100]
               YLim: [-363.6000 3.6000]
             XScale: 'log'
             YScale: 'linear'
      GridLineStyle: '-'
           Position: [0.5425 0.1100 0.3625 0.1580]
              Units: 'normalized'
    

    这可能是右下图 . 对象搜索也可以按逻辑条件过滤:

    lineHandle = findobj(gcf,'Type','line','-and','Color','b');
    

    但是我担心为特定的函数图分配一个行句柄最终会尝试错误...

相关问题