Adding new circle to plot at constant frequency
Afficher commentaires plus anciens
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:60
figure
if i>=1 && i<20
x=10;
r=0.4;
y=18;
axis ([0 20 0 20])
hold on
th = 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<40
x=10;
r=0.4;
y=14;
axis ([0 20 0 20])
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y+2;
h = plot(xunit, yunit);
hold off
hold on
th = 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 on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y+4;
h = plot(xunit, yunit);
hold off
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y+2;
h = plot(xunit, yunit);
hold off
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
h = plot(xunit, yunit);
hold off
end
end
end
Figures that I got is like

and

and

%
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Polar Plots 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!