how do i get the color gray

 Respuesta aceptada

Hans Scharler
Hans Scharler el 13 de Mayo de 2022
Editada: Hans Scharler el 23 de En. de 2024
As others have pointed out, gray is the result of the Red, Green, and Blue values being equal somewhere between 0 and 1 where black is [0 0 0] and white is [1 1 1].
x = rand(200,4);
y = rand(200,4);
grayColor = [.7 .7 .7];
plot(x, y, 'Color', grayColor)
If you are you used to 255 color values from HTML for example, you can divide by 255 to get a value between 0 and 1. Classic HTML gray is [128, 128, 128].
x = rand(200,4);
y = rand(200,4);
htmlGray = [128 128 128]/255;
plot(x, y, 'Color', htmlGray)

1 comentario

Steven Lord
Steven Lord el 23 de En. de 2024
And if you want to select a particular color interactively then hard-code that color value into your app, open the uisetcolor dialog box. Select the shade that matches what you want from the dialog then close the dialog. The color value will be displayed in the Command Window, ready for you to copy and paste into the app.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 23 de Mayo de 2012

6 votos

Gray is any RGB color with Red, Green, and Blue components all equal, excepting black (all 0's) and white (all components the maximum).
For example,
plot(x, y, 'Color', [17 17 17])

4 comentarios

Khaled Baha
Khaled Baha el 29 de En. de 2020
it doesnt work
plot(x, y, 'Color', uint8([17 17 17]))
or
plot(x, y, 'Color', [17 17 17]/255)
Zhe Chen
Zhe Chen el 28 de Jul. de 2020
must be in the range (0 1)
Which MATLAB release are you using?
plot(rand(1,5), 'Color', uint8([17 17 17]))
hold on
plot(rand(1,5), 'Color', [17 17 17]/255)
hold off
works for me.
Note that there are some plot attributes that only accept floating point, such as most Alpha values. In that case you would need the /255 form.

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 23 de Mayo de 2012

Comentada:

el 23 de En. de 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by