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

1 view (last 30 days)
dunphy
dunphy on 10 Nov 2021
Commented: dunphy on 15 Nov 2021
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 Comment
Star Strider
Star Strider on 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.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 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 Comments
Star Strider
Star Strider on 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)
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.
.

Sign in to comment.

More Answers (1)

Kevin Holly
Kevin Holly on 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 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!