0
votes

I would like to visualize different responses of different systems in a single plot with Matlab's control toolbox, and to colorize the various curves so it is easy to differentiate between the different systems.

The response plots are easily created using the control toolbox - e.g. step response (using step), response to an arbitrary input (using lsim), etc.

When using separate model objects for different systems, It's easy to create multi-color plots, e.g., for a step response: step(Sys1, 'b', Sys2, 'r') would give one blue curve and one red cure, if Sys1 and Sys2 are both a single system model.

However, if plotting a model array, there's no way to differentiate between the various curves that belong to the same array. E.g.: step(SysArray, 'b') would make all curves blue. step(Sys,'b','r') is invalid - so no easy way to specify various colors. Also, using the "Edit Plot" tool, selecting one curve effectively selects all curves, and any changes to the properties (e.g. line color) would affect all curves.

Is there any way to control the properties of each curve separately?

2

2 Answers

0
votes

There's no built-in function to do this, so you have to roll your own functionality

% 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
0
votes

@Phil Goddard

There's no built-in function to do this, so you have to roll your own functionality

% 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

Thanks for the code! Here are some slight changes to work better with model sampling through parameter variation, including the colorbar. I was hoping it would also work with pzmap, for example, but it creates 2*n lines (poles and zeros), so it would need a bit more work.

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