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.
Syntax
Description
Examples
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]);
Set the color of the polygon to yellow.
setColor(h,"yellow");
Input Arguments
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 Name | Short Name | RGB Triplet | Appearance |
|---|---|---|---|
"red" | "r" | [1 0 0] |
|
"green" | "g" | [0 1 0] |
|
"blue" | "b" | [0 0 1] |
|
"cyan"
| "c" | [0 1 1] |
|
"magenta" | "m" | [1 0 1] |
|
"yellow" | "y" | [1 1 0] |
|
"black" | "k" | [0 0 0] |
|
"white" | "w" | [1 1 1] |
|
This table lists the default color palettes for plots in the light and dark themes.
| Palette | Palette Colors |
|---|---|
Before R2025a: Most plots use these colors by default. |
|
|
|
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 R2008aStarting in R2018b, a new set of ROI objects replaces the existing set of ROI objects. The new objects provide more functional capabilities, such as face color transparency. The new classes also support events that you can use to respond to changes in your ROI such as moving or being clicked. Although there are no plans to remove the old ROI objects at this time, switch to the new ROIs to take advantage of the additional capabilities and flexibility. For more information on creating ROIs using the new ROI functions, see Create ROI Shapes.
To set the color of the new ROIs, set the value of the Color
property.
Update all instances of setColor.
| Discouraged Usage | Recommended Replacement |
|---|---|
This example creates an ROI and uses
imshow("cameraman.tif"); h = imrect(gca,[10 10 100 100]); setColor(h,"yellow"); | Replace the ROI with the equivalent new ROI object.
Then, delete the call to imshow("cameraman.tif"); h = drawrectangle(gca,"Position",[10 10 100 100]); h.Color = "yellow" |
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)