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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)