How to get different colours in a matrix with imagesc?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
i created a matrix and within the matrix there is a circle of red dots.
i need all the dots to have different colours (red, blue, green) on a random basis, but i dont know how to do it.
here is my code:
m1 = zeros(400,400,3);
center = round(size(m1)/2);
ecc = (rand(1,1000).^0.5).*100;
pol = rand(1,1000).*360;
x = round(cosd(pol) .* ecc); y = round(sind(pol) .* ecc);
m1(sub2ind(size(m1),center(1)-y, center(2)+x)) = 3;
figure; imagesc(m1)
i want to do it with a "for" loop like this
for i = 1:3
ecc = (rand(1,1000).^0.5).*100, i;
pol = rand(1,1000).*360, i;
end
or something like this:
for i = 1:3
ecc = (rand(1,1000, i).^0.5).*100;
pol = rand(1,1000, i).*360;
end
i am very new to matlab and i even fail to figure out where in this code the colour can be placed.
i just know that colour for a very simple matrix works like this:
mat(3,4,1) = 1; %red
mat(5,6,2) = 1; %green
mat(1,2,3) = 1; %blue
thanks for help :)
0 comentarios
Respuesta aceptada
jonas
el 10 de Nov. de 2018
Editada: jonas
el 10 de Nov. de 2018
I made an attempt at fixing your code. What you describe with colors is for RGB images, to display with imshow not imagesc. For imagesc you can simply work with 2D matrices and a suitable colormap.
m1 = zeros(400,400,1);
center = round(size(m1)/2);
ecc = (rand(1,1000).^0.5).*100;
pol = rand(1,1000).*360;
x = round(cosd(pol) .* ecc); y = round(sind(pol) .* ecc);
m1(sub2ind(size(m1),center(1)-y, center(2)+x)) = randi([1 3],1,1000);
figure;
colormap([0 0 0;1 0 0;0 1 0;0 0 1])
imagesc(m1)
0 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Orange en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!