自定义多个根轨迹图颜色(灰色比例)Matlab
Customizing multiple rootlocus plot colors (scale of grey) Matlab
我想自定义根轨迹图的颜色。
我使用 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
利用rlocus()
function is not as powerful as the plot()
function and only has limited support for setting colours with rlocus(sys, 'b')
as you've noticed. However, we can combine it with the plot()
函数的威力。
这里我使用[R, K] = rlocus(sys)
to return the values of the root locus, R
. Each row of R
represents a different trajectory. We can plot 1 trajectory of the root locus with plot(R(m, :))
and utilise the strength of 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
我想自定义根轨迹图的颜色。 我使用 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
利用rlocus()
function is not as powerful as the plot()
function and only has limited support for setting colours with rlocus(sys, 'b')
as you've noticed. However, we can combine it with the plot()
函数的威力。
这里我使用[R, K] = rlocus(sys)
to return the values of the root locus, R
. Each row of R
represents a different trajectory. We can plot 1 trajectory of the root locus with plot(R(m, :))
and utilise the strength of 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