【问题标题】:Customizing multiple rootlocus plot colors (scale of grey) Matlab自定义多个根轨迹图颜色(灰色比例)Matlab
【发布时间】:2015-12-21 07:01:59
【问题描述】:

我想自定义我的根轨迹图的颜色。 我使用 for 循环来绘制 10 个根位点(循环中的系统略有不同),我希望它们中的每一个都具有不同的灰色阴影。我想使用 gray 命令获取一个矩阵来存储 RGB 数据,然后在 rlocus(sys,K,'style') 命令中使用这个矩阵(在我的循环的第 i 次迭代中选择第 i 行)。不幸的是,该命令要求样式为单元格(例如“g”或“b”)而不是数字向量。

这是我的代码示例:

figure()
hold on
L = [sys1, sys2, ..., sys10];
colors = gray(10);
for i = 0:9
 rlocus (L(i+1), 'Color', colors(i+1, :));
end

【问题讨论】:

  • 我有一个想法,但如果你发布你已经拥有的代码会有所帮助。您应该查看How to Askminimal reproducible example,然后回到这里编辑您的问题,以便我们更轻松地回答。
  • 我已经编辑了这个问题。谢谢!

标签: matlab plot colors customization grayscale


【解决方案1】:

rlocus() 函数不如plot() 函数强大,并且您已经注意到,仅对使用rlocus(sys, 'b') 设置颜色提供有限支持。但是,我们可以将其与plot() 函数结合使用以发挥其强大功能。

这里我使用[R, K] = rlocus(sys) 来返回根轨迹R 的值。 R 的每一行代表不同的轨迹。我们可以用plot(R(m, :))绘制根轨迹的1个轨迹,并利用plot()的力量来改变我们想要的颜色。

L = [sys1, sys2, sys3, sys4, sys5, sys6, sys7, sys8, sys9, sys10];
C = gray(numel(L) + 1); % Extra 1 because the last value will be
                        % white and plotting white on white does
                        % not look well :P

figure;
hold on
for n = 1:numel(L)
    [R, K] = rlocus(L(n));

    for m = 1:numel(R)/length(R)
        plot(R(m, :), 'Color', C(n, :));
    end
end
hold off

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-15
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多