How to create a colored, with three equally spaced rows of colors horizontally with a dimension of 6x5x3
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/796304/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/796304/image.png)
I got this output but I need it to be horizontal.
1 commentaire
Star Strider
le 10 Nov 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.
Réponse acceptée
Star Strider
le 10 Nov 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 commentaires
Star Strider
le 11 Nov 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)
would do the same thing, so my code would use it as —
colormap(tci1)
with the same result.
.
Plus de réponses (1)
Kevin Holly
le 10 Nov 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 commentaires
Kevin Holly
le 11 Nov 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]
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
you can also select arrays as inputs
m(2:3,2:3)
I selected the first column using a colon (:) to select all the rows and 1 to select the first column.
m(:,1)
Voir également
Catégories
En savoir plus sur Red dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!