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
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
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 件のコメント
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)
would do the same thing, so my code would use it as —
colormap(tci1)
with the same result.
.
その他の回答 (1 件)
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
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]
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)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!