Main Content

uisetcolor

Open color picker

Description

c = uisetcolor displays a modal color picker and returns the selected color as an RGB triplet. The RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the selected color. The intensities are in the range [0,1] and are of type double.

example

c = uisetcolor(RGB) specifies the default color selection as an RGB triplet.

c = uisetcolor(obj) sets the default color selection to be the color of an object (such as a Figure). If you select a different color in the color picker, the color of the object changes to the new color after you click OK. The object must have a property that controls some aspect of color. For example, some objects have a Color or BackgroundColor property.

example

c = uisetcolor(___,title) specifies a custom title for the dialog box. Specify the title as the last argument for any of the above syntaxes.

Examples

collapse all

Open the color picker with light blue as the default color.

c = uisetcolor([0.6 0.8 1])

Color picker. The window contains images of standard colors, recent colors, and a preview of the default light blue color. There are OK and Cancel buttons at the bottom of the window.

Clicking the OK button without selecting a different color returns the default color.

c =

     0.6000    0.8000    1.0000

Open the color picker with yellow as the default color and set the title to 'Select a Color'.

c = uisetcolor([1 1 0],'Select a color')

Color picker. The window displays Select a color at the top. The yellow color is selected.

Clicking the OK button without selecting a different color returns the default color.

c =

     1     1     0

Starting in R2018b, the color picker provides a tab for selecting custom colors from a gradient.

Open the color picker, and click the Custom Colors tab in the upper-right corner.

c = uisetcolor

Color picker. The Custom Colors tab is selected. The window displays a box with a color gradient, a color slider, a drop-down with RBG selected, the RGB values of the selected color, and a preview of the selected color.

Move the vertical slider to display the desired region of color space. Then click the color gradient to select a color. When you click OK, uisetcolor returns your selection as an RGB triplet.

Color picker before and after selecting a new color. On the left, selecting a new color using the slider updates the gradient. On the right, selecting a point in the gradient updates the RGB values and the color preview.

c =

     0.4471    0.9020    0.1451

Input Arguments

collapse all

Default color, specified as an RGB triplet. An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the selected color. The intensities must be in the range [0,1].

Example: c = uisetcolor([1 0 0]) specifies red as the default color selection.

Example: c = uisetcolor([0.5 0.5 0.5]) specifies gray as the default color selection.

Data Types: single | double

Source object for default color, specified as a graphics object. The object must have a property that controls some aspect of color. For example, some objects have a Color or BackgroundColor property.

Example: c = uisetcolor(figure) creates a Figure and sets the default color selection to be the same color as the figure.

Title of dialog box, specified as a character vector or string scalar.

Example: c = uisetcolor('Choose a Color') specifies 'Choose a Color' as the dialog box title.

Data Types: char

More About

collapse all

Modal Window

A window that blocks interaction with other windows until the user closes it.

Introduced before R2006a