模型阵列图中不同模型的着色(Matlab)

模型阵列图中不同模型的着色(Matlab),matlab,plot,Matlab,Plot,我想用Matlab的控制工具箱将不同系统的不同响应可视化到一个图中,并将各种曲线着色,以便容易区分不同的系统 使用控制工具箱可以轻松创建响应图-例如阶跃响应(使用step)、对任意输入的响应(使用lsim)等 当为不同的系统使用单独的模型对象时,很容易创建多色图,例如,对于阶跃响应:step(Sys1,'b',Sys2,'r')将给出一条蓝色曲线和一条红色曲线,如果Sys1和Sys2都是单个系统模型 但是,如果打印模型阵列,则无法区分属于同一阵列的各种曲线。例如:步骤(SysArray,'b')

我想用Matlab的控制工具箱将不同系统的不同响应可视化到一个图中,并将各种曲线着色,以便容易区分不同的系统

使用控制工具箱可以轻松创建响应图-例如阶跃响应(使用
step
)、对任意输入的响应(使用
lsim
)等

当为不同的系统使用单独的模型对象时,很容易创建多色图,例如,对于阶跃响应:
step(Sys1,'b',Sys2,'r')
将给出一条蓝色曲线和一条红色曲线,如果Sys1和Sys2都是单个系统模型

但是,如果打印模型阵列,则无法区分属于同一阵列的各种曲线。例如:
步骤(SysArray,'b')
会使所有曲线变蓝<代码>步骤(Sys,'b','r')无效-因此无法简单地指定各种颜色。 此外,使用“编辑绘图”工具,选择一条曲线可以有效地选择所有曲线,并且对特性的任何更改(例如线颜色)都会影响所有曲线


有没有办法单独控制每条曲线的属性?

没有内置的功能来实现这一点,因此您必须使用自己的功能

% Create n-by-3 array of colours to use
coloursArray = rand(numel(stackedSystems),3); % for this example put in random colours
% Do the plot
step(stackedSystems);
title('My custom title');
grid on
% Change colours
ha = findobj(gcf,'type','axes','visible','on'); % Get handles of all axes (for MIMO responses)
for jdx = 1:numel(ha)
   hl = findobj(ha(jdx),'type','line','visible','on'); % Get handles to all lines
   for idx = 1:numel(hl)
       set(hl(idx),'Color',coloursArray(idx,:));  %  Change the colour
   end
end
% Create n-by-3 array of colours to use
coloursArray = rand(numel(stackedSystems),3); % for this example put in random colours
% Do the plot
step(stackedSystems);
title('My custom title');
grid on
% Change colours
ha = findobj(gcf,'type','axes','visible','on'); % Get handles of all axes (for MIMO responses)
for jdx = 1:numel(ha)
   hl = findobj(ha(jdx),'type','line','visible','on'); % Get handles to all lines
   for idx = 1:numel(hl)
       set(hl(idx),'Color',coloursArray(idx,:));  %  Change the colour
   end
end
@菲尔·戈达德


没有内置的函数来执行此操作,因此您必须滚动鼠标 自身功能

% Create n-by-3 array of colours to use
coloursArray = rand(numel(stackedSystems),3); % for this example put in random colours
% Do the plot
step(stackedSystems);
title('My custom title');
grid on
% Change colours
ha = findobj(gcf,'type','axes','visible','on'); % Get handles of all axes (for MIMO responses)
for jdx = 1:numel(ha)
   hl = findobj(ha(jdx),'type','line','visible','on'); % Get handles to all lines
   for idx = 1:numel(hl)
       set(hl(idx),'Color',coloursArray(idx,:));  %  Change the colour
   end
end
% Create n-by-3 array of colours to use
coloursArray = rand(numel(stackedSystems),3); % for this example put in random colours
% Do the plot
step(stackedSystems);
title('My custom title');
grid on
% Change colours
ha = findobj(gcf,'type','axes','visible','on'); % Get handles of all axes (for MIMO responses)
for jdx = 1:numel(ha)
   hl = findobj(ha(jdx),'type','line','visible','on'); % Get handles to all lines
   for idx = 1:numel(hl)
       set(hl(idx),'Color',coloursArray(idx,:));  %  Change the colour
   end
end
谢谢你的代码! 下面是一些细微的更改,通过参数变化(包括颜色条)更好地使用模型采样。 例如,我希望它也能与pzmap一起工作,但它会创建2*n条线(极点和零点),因此需要更多的工作

function colorSamplingPlot(values,var)
% values is an array with parameter value assigned to each curve
% var is a string for the colorbar label

n = numel(findobj(gca,'type','line','visible','on'));

% Create n-by-3 array of colours to use
coloursArray = colormap(jet(n));

% Change colours
% Get handles of all axes (for MIMO responses)
ha = findobj(gcf,'type','axes','visible','on');

for jdx = 1:numel(ha)

    % Get handles to all lines
    hl = findobj(ha(jdx),'type','line','visible','on');

    for idx = 1:numel(hl)

        %  Change the color; inverted color order to match colorbar
        set(hl(idx),'Color',coloursArray(numel(hl)-idx+1,:));
    end
end

colorbar;
caxis([min(values),max(values)]);

hcb = colorbar;
hcb.Label.String = vars;

end

很抱歉我的回复很晚,谢谢你的回答。除了第一行中的
numel(stackedSystems)
之外,该代码运行良好,它不返回模型数组中的实际系统数。