View License

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

» Watch video

Highlights from

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

Be the first to rate this file! 0 Downloads (last 30 days) File Size: 2.96 KB File ID: #41533 Version: 1.0
image thumbnail



Jurgen (view profile)


Apply color CLR to colormap entry pertaining to value VAL. Either scaled or indexed figure.

| Watch this File

File Information

Extension of zerocolor() for arbitrary color. Greater control over colormaps allows user to increase contrast for particular values.

% valcolor(VAL,CLR)
% Updates current figure's colormap so values VAL get color CLR.
% This includes values mapped to the same color as VAL.
% CLR is either a vector between 0-1, e.g. [.4 .2 .9] or
% a standard MATLAB color string shorthand, e.g. 'r'.
% Based on Clim and CDataMapping value of current axes and image.
% valcolor(H,VAL,CLR) uses figure handle H instead of current.
% cmap = valcolor(...)
% Returns modified cmap based on figure's colormap.
% Does not apply it to figure. Apply with colormap().
% cmap = valcolor(VAL,CLR,oldmap,clims)
% Outputs colored cmap based on input map and clims.
% May supply data instead of clims, gets [min max] to create clims.
% If clims = false, assumes indexed colormap.

im1 = imread('moon.tif'); %scaled
figure;imagesc(im1);axis off
valcolor(50,[1 0 0 ])
valcolor(200,[1 1 0 ])

im2 = load('clown'); %indexed
valcolor(0,[0 1 0]);
valcolor(40,[0 0 0]);
valcolor(60,[0 1 1]);


Custom Colormap and Zerocolor inspired this file.

Required Products MATLAB
MATLAB release MATLAB 7.6 (R2008a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.

Contact us