Code covered by the BSD License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

### Highlights from Find unused plot color

5.0
5.0 | 1 rating Rate this file 1 Download (last 30 days) File Size: 1.67 KB File ID: #37137 Version: 1.1

# Find unused plot color

by

### Deborah (view profile)

12 Jun 2012 (Updated )

Find the first unused default color in a plot or generate a random one.

File Information
Description

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
plot(x,y,'color', which_color(gca))

It first uses all the specified colors in the ColorOrder. If all of them are used it generates a random color.

Required Products MATLAB
MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Comments and Ratings (3)
21 Jun 2012 Jan Simon

### Jan Simon (view profile)

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.

13 Jun 2012 Deborah

### Deborah (view profile)

Thanks again Jan for your suggestions to improve the code quality, I'll soon upload an updated version!

Comment only
12 Jun 2012 Jan Simon

### Jan Simon (view profile)

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.

Comment only