Hello,
I am trying to plot figures that have a circle inside it. I want to add a new circle to the figure at a constant frequency. let us say each 20 steps. For example, if I have 60 steps then I should have 60 figures. Figures from 1 to 20 will have one circle, figures from 21 to 40 will have 2 circles, and figures from 41 to 60 will have three circles. I did that in below code and it is working properly. However, I used if condition in my code. The problem if I will have 1000 steps this mean I need to use (1000/20= 50) if condition and that does not make sense. Is there any sufficient way to do that. This is an example.In my real case, I will have from step 1-20 circle moving at each step from step 21-40 I will have two circles moving and so on. I gave this example to make the situation easy. I have the location (x,y) for all steps stored in one matrix.
function h = circle(x,y,r)clc;for i=1:60figureif i>=1 && i<20 x=10;r=0.4;y=18;axis ([0 20 0 20])hold onth = 0:pi/50:2*pi;xunit = r * cos(th) + x;yunit = r * sin(th) + y;h = plot(xunit, yunit);hold off elseif i>=20 && i<40x=10;r=0.4;y=14;axis ([0 20 0 20]) hold onth = 0:pi/50:2*pi;xunit = r * cos(th) + x;yunit = r * sin(th) + y+2;h = plot(xunit, yunit);hold offhold onth = 0:pi/50:2*pi;xunit = r * cos(th) + x;yunit = r * sin(th) + y;h = plot(xunit, yunit);hold off else i>=40 && i<60;x=10;r=0.4;y=10;axis ([0 20 0 20])hold onth = 0:pi/50:2*pi;xunit = r * cos(th) + x;yunit = r * sin(th) + y+4;h = plot(xunit, yunit);hold offhold onth = 0:pi/50:2*pi;xunit = r * cos(th) + x;yunit = r * sin(th) + y+2;h = plot(xunit, yunit);hold offhold onth = 0:pi/50:2*pi;xunit = r * cos(th) + x;yunit = r * sin(th) + y;h = plot(xunit, yunit);hold offend end end
Figures that I got is like
and
and
%
Best Answer