How to create a colored, with three equally spaced rows of colors horizontally with a dimension of 6x5x3

3 visualizaciones (últimos 30 días)
yellow = [1,1,0]
orange = [0.8500,0.3250,0.0980]
pink = [1, 0.5, 0.8]
tci = cat (3,yellow,orange,pink)
image (tci)
I
I got this output but I need it to be horizontal.
  1 comentario
Star Strider
Star Strider el 10 de Nov. de 2021
The image function will not correctly render the colours defined in the posted code.
The patch function will.
It is then straightforward to convert the patch plot into an image if that is the desired result. Simply use the saveas function.

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 10 de Nov. de 2021
Try this —
yellow = [1,1,0];
orange = [0.8500,0.3250,0.0980];
pink = [1, 0.5, 0.8];
tci = cat (3,yellow,orange,pink);
x = [0 3 3 0; 0 3 3 0; 0 3 3 0];
y = [0 0 1 1; 1 1 2 2; 2 2 3 3];
figure
hp = patch(x', y', (0:2).');
colormap([yellow; orange; pink])
Change the order of the colours in the colormap call to order them differently.
.
  2 comentarios
dunphy
dunphy el 11 de Nov. de 2021
this is great ! may i know what this code commands?
m = [yellow;orange;pink];
tci = cat(3,m(:,1),m(:,2),m(:,3));
Star Strider
Star Strider el 11 de Nov. de 2021
Thank you!
I do not use that in my code, however it defines a colormap that MATLAB uses to define the colours in a graphics object.
My code defines it as —
colormap([yellow; orange; pink])
with the same effect.
NOTE — This assignment (note the significant change from the original code):
yellow = [1,1,0];
orange = [0.8500,0.3250,0.0980];
pink = [1, 0.5, 0.8];
tci1 = cat (1,yellow,orange,pink)
tci1 = 3×3
1.0000 1.0000 0 0.8500 0.3250 0.0980 1.0000 0.5000 0.8000
would do the same thing, so my code would use it as —
colormap(tci1)
with the same result.
.

Iniciar sesión para comentar.

Más respuestas (1)

Kevin Holly
Kevin Holly el 10 de Nov. de 2021
If you want the image above to be horizontal:
yellow = [1,1,0];
orange = [0.8500,0.3250,0.0980];
pink = [1, 0.5, 0.8];
tci = cat(3,yellow',orange',pink');
image (tci)
What do mean when you state that you want a dimension of 6x5x3? This?
tci2 = imresize(tci,[6 5]);
image (tci2)
Are these the colors that you were expecting?
  5 comentarios
Kevin Holly
Kevin Holly el 11 de Nov. de 2021
I created a matrix called m that contained the 3 RGB pixels you defined.
yellow = [1,1,0];
orange = [0.8500,0.3250,0.0980];
pink = [1, 0.5, 0.8];
m = [yellow;orange;pink]
m = 3×3
1.0000 1.0000 0 0.8500 0.3250 0.0980 1.0000 0.5000 0.8000
The first row was a yellow pixel defined as [1 1 0], which gives red the value of 1, green a value of 1, and blue a value of 0, i.e. [R G B].
tci = cat(3,m(:,1),m(:,2),m(:,3));
The cat function you were using accepts matrices that represent red, green, and blue when defining the dimension to be 3.
Knowing the first column in the matrix represents red, the second green, and the third blue, I inserted each column into the cat function.
cat(3,red,green,blue), where red = m(:,1)
To select specific points in a matrix, in this case called m, you can write the following
m(row,column)
m(2,3) %This selects the value on the second row and third column of matrix m
ans = 0.0980
you can also select arrays as inputs
m(2:3,2:3)
ans = 2×2
0.3250 0.0980 0.5000 0.8000
I selected the first column using a colon (:) to select all the rows and 1 to select the first column.
m(:,1)
ans = 3×1
1.0000 0.8500 1.0000

Iniciar sesión para comentar.

Categorías

Más información sobre Red en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by