主要内容

setColor

(Not recommended) Set color used to draw ROI object

setColor is not recommended. With the new ROIs, set the value of the Color property instead. For more information, see Version History.

Description

setColor(h,color) sets the color used to draw the ROI object h.

example

Examples

collapse all

Display an image. Draw a polygon on the image, specifying the location of five vertices.

imshow("gantrycrane.png")
h = impoly(gca,[188,30; 189,142; 93,141; 13,41; 14,29]);

Closed polygon drawn in blue over an image.

Set the color of the polygon to yellow.

setColor(h,"yellow");

Polygon color changed to yellow.

Input Arguments

collapse all

ROI object, specified as an imellipse, imfreehand, imline, impoint, impoly, or imrect object.

ROI color, specified as an RGB triplet, a color name, or a short color name.

You can specify any color using an RGB triplet. An RGB triplet is a 3-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0, 1].

You can specify some common colors by name as a string scalar or character vector. This table lists the named color options and the equivalent RGB triplets.

Color NameShort NameRGB TripletAppearance
"red""r"[1 0 0]

Sample of the color red

"green""g"[0 1 0]

Sample of the color green

"blue""b"[0 0 1]

Sample of the color blue

"cyan" "c"[0 1 1]

Sample of the color cyan

"magenta""m"[1 0 1]

Sample of the color magenta

"yellow""y"[1 1 0]

Sample of the color yellow

"black""k"[0 0 0]

Sample of the color black

"white""w"[1 1 1]

Sample of the color white

This table lists the default color palettes for plots in the light and dark themes.

PalettePalette Colors

"gem" — Light theme default

Before R2025a: Most plots use these colors by default.

Sample of the "gem" color palette

"glow" — Dark theme default

Sample of the "glow" color palette

You can get the RGB triplets for these palettes using the orderedcolors function (since R2023b). For example, get the RGB triplets for the "gem" palette.

RGB = orderedcolors("gem");

Example: "r"

Example: "green"

Example: [0 0.4470 0.7410]

Version History

Introduced in R2008a

collapse all

See Also

|