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

1 visualización (últimos 30 días)
Jassy
Jassy el 24 de Abr. de 2019
Respondida: Akira Agata el 24 de Abr. de 2019
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.

Respuesta aceptada

Akira Agata
Akira Agata el 24 de Abr. de 2019
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

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by