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

조회 수: 4 (최근 30일)
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
Star Strider
Star Strider 2021년 11월 10일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2021년 11월 10일
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
dunphy
dunphy 2021년 11월 11일
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 2021년 11월 11일
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.
.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Kevin Holly
Kevin Holly 2021년 11월 10일
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
Kevin Holly
Kevin Holly 2021년 11월 11일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by