problem with scatter/bubble plot

조회 수: 4 (최근 30일)
germ
germ 2011년 12월 28일
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

채택된 답변

bym
bym 2011년 12월 28일
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
germ
germ 2011년 12월 29일
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 2011년 12월 29일
second line should be:
t(61) = [ ];

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

the cyclist
the cyclist 2011년 12월 28일
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
germ
germ 2011년 12월 28일
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 :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by