problem with scatter/bubble plot

hi,
i have created a vector containing coordinates of a circle in a matrix.
i want to display these locations as dots in a plot.further i want to color these dots in a clockwise increasing color scheme. i have written a code but experienced a problem : the color vector which i created does not seem to be mapped linearly to my location points
code:
matrix = ones(512,512);
mittelpunkt_x = 256;
mittelpunkt_y = 256;
radius = 33;
for i=1:size(matrix,1)
for j = 1:size(matrix,2)
matrix(i,j) = norm([i j]-[mittelpunkt_x,mittelpunkt_y],2);
if matrix(i,j)<=radius
matrix(i,j)=0;%10;
elseif matrix(i,j)<radius+1 && matrix(i,j)>radius
matrix(i,j)=1;
else
matrix(i,j)=0;
end
end
end
b=0.00490196078
[r,c]=find(matrix==1);
color=[b:b:1];
y=[r c];
scatter(r,c,50,color,'filled')
i hope someone can help me with this
g3rm9

 Réponse acceptée

bym
bym le 28 Déc 2011

0 votes

something like this?
t = 0:pi/6:2*pi
t(13)=[];
x = cos(t);
y = sin(t);
c = spring(12);
scatter(x,y,[],c,'filled')

4 commentaires

germ
germ le 29 Déc 2011
Wow thank you proecsm !
yes i searched for something like this. it seems a lot easier than my method of
getting the locations.
i still have some questions : what does the second line do(t(13)=[];)
and how would i get this animated(turn the circle). i thought of the circshift
command (c2=circshift(c, [-1, 0]);) but am not shure how to create a gif out of this: do i have to create 60 (using t = 0:pi/30:2*pi) single scatterplots and somehow merge them ?
or is there another way of doing this
bym
bym le 29 Déc 2011
you will notice my original array contains both 0 and 2*pi. To avoid plotting that point twice, I just delete the last point.
t(13)=[] %delete the last point.
as far as animation, you'll have to do that in a loop. look at the documentation for
getframe()
germ
germ le 29 Déc 2011
thank you alot !
my final code is :
t = 0:pi/30:2*pi
t(60)=[];
x = cos(t);
y = sin(t);
c = jet(60);
z = zeros(60,3);
z(1,:)=[1 0 0];
for j=1:60;
scatter(x,y,[],circshift(c, [-j,0]),'filled')
axis equal;
F(j) = getframe;
end
movie(F,2)
the only thing i wonder is why the 17th point seems to be missing
bym
bym le 29 Déc 2011
second line should be:
t(61) = [ ];

Connectez-vous pour commenter.

Plus de réponses (1)

the cyclist
the cyclist le 28 Déc 2011

0 votes

I'm not sure I understand what the problem is. When I run your code, I see a circle with varying color going around it, which I assume is what you want. It may not look like a circle, because the displayed axes do not have equal aspect ratio. You may want to put the following code after your scatter() command:
>> axis equal
>> axis square
If that is not what you mean, then you will need to be more explicit by what "mapped linearly to my location points" means.

1 commentaire

germ
germ le 28 Déc 2011
thank you for the quick reply !
yes i may have not been very explicit with my question.
when i run the upper code i see the colored circle.what i want is a smooth flow from ie: yellow to red. through the whole circle. in the current plot the colorvariation from yellow to red only reaches from the 1 point to half of the circle then the color decreases in the second part ending with the 1 and last point being the same color.
at the current state i have modified my code to :
matrix = ones(50,50);
mittelpunkt_x = 25;
mittelpunkt_y = 25;
radius = 11;
for i=1:size(matrix,1)
for j = 1:size(matrix,2)
matrix(i,j) = norm([i j]-[mittelpunkt_x,mittelpunkt_y],2);
if matrix(i,j)<=radius
matrix(i,j)=0;%10;
elseif matrix(i,j)<radius+1 && matrix(i,j)>radius
matrix(i,j)=1;
else
matrix(i,j)=0;
end
end
end
%figure
%imshow(matrix,[0 10]);
[r,c]=find(matrix==1);
farbe=rand(1,60);
R = zeros(60,1);
G = zeros(60,1);
B = zeros(60,1);
R(:,1)=1;
G0=[1/60:1/60:1];
G=G0';
R(20,1)=0;
G(20,1)=0;
B(20,1)=0;
RGB = [R G B];
y=[r c]; %r=x-koordinate c=y-koordinate
z=matrix(:);
figure
scatter(r,c,50,RGB,'filled')
axis equal
axis square
R2 = R([60 1:59],1);
G2 = G([60 1:59],1);
B2 = B([60 1:59],1);
RGB2=[R2 G2 B2];
figure
scatter(r,c,50,RGB2,'filled')
axis equal
axis square
R3 = R2([60 1:59],1);
G3 = G2([60 1:59],1);
B3 = B2([60 1:59],1);
RGB3=[R3 G3 B3];
figure
scatter(r,c,50,RGB3,'filled')
R4 = R3([60 1:59],1);
G4 = G3([60 1:59],1);
B4 = B3([60 1:59],1);
RGB4=[R4 G4 B4];
figure
scatter(r,c,50,RGB4,'filled')
axis equal
axis square
for i want the circle to have 60 locations imitating a clock .
the second change i made is that i generated multiple plots cause i want to do a animation of the circle. means making it turn(i'm still not sure how to realize this but am working on it)
i hope you can imagine what i mean :)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by