Whenever plots are generated inside a loop with the figure put on hold, the normal plot command plots everything in the same color. When a different color is wanted, normally a color-vector needs to be generated.
With this function it is possible to call the color inside the plot command, using
It first uses all the specified colors in the ColorOrder. If all of them are used it generates a random color.
Works as explained in the help text, has a H1-line to support LOOKFOR, date, author, version history, comments in the code, efficient, useful and usable.
Thanks again Jan for your suggestions to improve the code quality, I'll soon upload an updated version!
The function fails, if a line was drawn using a CHAR color specifier as 'r', 'g', 'b' etc.
The first line of the help text should be "not present in the axes", not "...in the figure".
"NaN(length(h_lines), 3)" is faster than "ones()*NaN". But ZEROS() would do it also, because all values are overwritten soon.
The search for the color can be simplified:
found = any(default_color(k,1)==curr_color(:,1) & default_color(k,2)==curr_color(:,2) & default_color(k,3)==curr_color(:,3));
Or an equivalent BSXFUN approach.
A simple "setdiff(default_color, curr_color, 'rows')" would reduce the code complexity also.
Instead of using the DefaultAxesColorOrder, you could use the ColorOrder of the actual axes object.
Simplified the way the color was determined thanks to Jan's suggestions.