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:
sys{1} = tf([1],[2 1])
sys{2} = tf([2],[2 3 1])
col = copper(numel(sys));
for ii = 1:numel(sys)
bodeplot(sys{ii},'b');
lineHandle = findobj(gcf,'Type','line','-and','Color','b');
set(lineHandle,'Color',col(ii,:));
hold on
end
hold off;
Best Answer