MATLAB: How to define the own colororder for a bodeplot

bodeplotcolororderrgb

Hi, I would like to plot up to 20 bodeplots in the same graph with a specified colororder. I have tried two different ways of doing this, but none of them works:
1) figure; color_order = copper(20); set(gcf,'DefaultAxesColorOrder',color_order) hold all for i = 1:20 bodeplot(models{i}); end
I have also tried by setting the default colororder for the whole matlab session with set(0,'DefaultAxesColorOrder',color_order), but this doesn't affect the color order for the bodeplot either.
2) figure;hold; color_order = copper(20); for i = 1:20 bodeplot(models{i},color_order(i)); end
Nr 2 does not work since bodeplot does not seem to take rgb-colors. I have also tried
figure;hold; color_order = copper(20); for i = 1:20 bodeplot(models{i},'Color',color_order(i)); end
Cheers, Anna-Maria

Best Answer

The function "bodeplot" defaults to colors specified in MATLAB. If you try to set a color order when using the "hold on" command, for each new plot, MATLAB uses the first value in the color order. In order to work around this, you will need to set the line colors to custom RGB values using the handles associated with the line objects. First you will have to obtain these handles associated with the line plots and then set their 'Color' property. You can find the handles associated with each line on the plot using the command:
lineHandle = findobj(gcf,'Type','line','-and','Color','b');
Here, the function "findobj" looks for objects in the figure of type "line" and color "b", and then obtains their handles.
Once you have these handles, you can then change the line color as per your requirements. You can do this by using the command:
set(lineHandle,'Color',col(ii,:));
The variable "col" contains the color order defined by "copper".
For more information on "findobj" please see: findobj
Here's a sample version of the code you want to execute:
% Define the models
sys{1} = tf([1],[2 1]) % Define one system
sys{2} = tf([2],[2 3 1]) % Define another system
% Define the color order based on the number of models
col = copper(numel(sys)); %
% Set the color to the color order you want
for ii = 1:numel(sys)
% Default the new plot color to blue
bodeplot(sys{ii},'b');
% Find handles of all lines in the figure that have the color blue
lineHandle = findobj(gcf,'Type','line','-and','Color','b');
% Change the color to the one you defined
set(lineHandle,'Color',col(ii,:));
% Hold on
hold on
end
% Hold off
hold off;