How to put the values into the specific area and put color

1 回表示 (過去 30 日間)
Jassy
Jassy 2019 年 4 月 24 日
回答済み: Akira Agata 2019 年 4 月 24 日
A = zeros(70);
I have 168 values is 1-4
Ex Values = { 1, 2, 3, 1, 2, 1, 1, 1, .....}
location is (15,15),(16,15),(17,15), ......... (27,15)
(15,16),(16,16),(17,16),............... (27,16)
(15,17),(16,17),(17,17),.................(27,17)
.
.
.
(15,27),(16,27),(17,27),............... (27,27)
and I want to input color on this location
1 = red
2 = green
3 = blue
4 = black
How to make this in loop?
Thank you.

採用された回答

Akira Agata
Akira Agata 2019 年 4 月 24 日
You don't need to use for-loop. The following is one possible solution.
A = zeros(70);
% Sample 168-by-1 random array with 1-4.
Values = randi(4,168,1);
% Sample 168-by-2 random array of location
[row,col] = ind2sub(size(A),randperm(numel(A),168));
Location = [row',col'];
% Create label matrix
Label = A;
Label(sub2ind(size(A),Location(:,1),Location(:,2))) = Values;
% Create RGB image
cmap = [...
1 0 0;... % red
0 1 0;... % green
0 0 1;... % blue
0 0 0]; % black
RGB = label2rgb(Label,cmap);
dots.png

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by