How can I plot circles, same radius and different centers, all in one graph. I used the following command to draw +,o,diamond: plot (x,y,'ro',u,v,'gd',A,B,'b+'); where x,y,u,v,A,B are all row vectors. And I want to add circles to that plot where the o will be the center.

댓글 수: 1

fatima ibrahim
fatima ibrahim 2020년 2월 29일
function draw_circle1(x,y,R,c)
t =0:0.05:6.28;
x1 = (x +R*cos(t))';
y1= (x +R*sin(t))';

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

 채택된 답변

Paulo Silva
Paulo Silva 2011년 3월 12일

15 개 추천

Here's a function to draw circles:
function circle(x,y,r)
%x and y are the coordinates of the center of the circle
%r is the radius of the circle
%0.01 is the angle step, bigger values will draw the circle faster but
%you might notice imperfections (not very smooth)
ang=0:0.01:2*pi;
xp=r*cos(ang);
yp=r*sin(ang);
plot(x+xp,y+yp);
end
If you want to add circles you must insert the command
hold on
before the circles being added.

댓글 수: 8

Firas
Firas 2014년 12월 29일
That's awesome
Eddie
Eddie 2017년 3월 15일
Thanks a lot, this is great. If I had some time, I would probably tweak your code and try to plot open intervals on the real line, that's what I really need, but circles are fine too.
Bud Kelly
Bud Kelly 2018년 4월 2일
There are coding solutions and there are coding solutions. The ones that accomplish the task as this one does are...elegant... beautiful... art. Thank you, you may consider it stolen! ;-)
passioncoding
passioncoding 2018년 8월 20일
I have been trying to create function for circle with function that mentioned above ,but I am getting this "Not enough input arguments" for "xp=r*cos(ang)". kindly help me in this regard
Image Analyst
Image Analyst 2018년 8월 20일
편집: Image Analyst 2018년 8월 20일
What is ang for you? Did you comment out or delete the line
ang=0:0.01:2*pi;
??? You did one or the other because if you didn't, ang would exist and you would not get that error.
Do you know how to debug by setting a breakpoint on that line and looking at its value? If not, see this link
Özgür Saglam
Özgür Saglam 2020년 5월 3일
what does 0.01 in ang mean? i dont understand this part
Rik
Rik 2020년 5월 3일
It's the step size. You can use the colon in two ways when you create an array:
start:stop
start:step:stop
Özgür Saglam
Özgür Saglam 2020년 5월 3일
Thank you very much!

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

추가 답변 (3개)

Michelle Hirsch
Michelle Hirsch 2016년 1월 29일

18 개 추천

It's counter-intuitive, but this is actually really easy with the rectangle function. From the rectangle documentation :
pos = [2 4 2 2];
rectangle('Position',pos,'Curvature',[1 1])
axis equal

댓글 수: 5

Image Analyst
Image Analyst 2016년 1월 29일
편집: Image Analyst 2022년 4월 15일
And with R2012a and later you can use viscircles
numCircles = 15;
x = 5 + randi(95, numCircles, 1);
y = 5 + randi(95, numCircles, 1);
radius = 2 * ones(numCircles, 1);
viscircles([x, y], radius);
grid on;
axis equal
Ronald Mintz
Ronald Mintz 2016년 4월 14일
Thanks very much Michelle. Your idea made beautiful concentric circles. viscircles didn't work on my computer because I have version R2011a.
Image Analyst
Image Analyst 2016년 4월 14일
편집: Image Analyst 2022년 4월 15일
rectangle() is one of several methods listed in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3F> You'll have lots of other nice improvements that they've made over the last 5 years if you upgrade.
numCircles = 15;
x = 5 + randi(95, numCircles, 1);
y = 5 + randi(95, numCircles, 1);
radius = 2 * ones(numCircles, 1);
viscircles([x, y], radius);
grid on;
axis equal
Royi Avital
Royi Avital 2023년 12월 10일
@Michelle Hirsch, It would be great if it had the DisplayName property like most other objects.
It makes easier when adding it to the legend.
Michelle Hirsch
Michelle Hirsch 2023년 12월 11일
@Royi Avital I think it's more than just adding DisplayName - annotations like rectangle (intentionally) don't show up in legend since they are meant to be annotations, not data. Are you interested in being able to include annotations in legend? If so, please share more about your use case so I make sure we understand what you are thinking.

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

Chad Greene
Chad Greene 2014년 8월 21일

0 개 추천

This'll do the job.
Image Analyst
Image Analyst 2016년 1월 20일
편집: Image Analyst 2022년 4월 15일

0 개 추천

numCircles = 15;
x = 5 + randi(95, numCircles, 1);
y = 5 + randi(95, numCircles, 1);
radius = 2 * ones(numCircles, 1);
viscircles([x, y], radius);
grid on;
axis equal

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2011년 3월 12일

댓글:

2023년 12월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by