Creating an ellipse plot with a for loop
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
For some reason my superellipse isn't shown in the figure when I run my code below in MatLab. I don't know where I went wrong, do I need to store the values in some way and then plot these values in the figure? Hope someone can help me out, thanks.
-Somehow the code underneath isn't shown correctly in the square on this website, sorry -
n=2;
a=1;
b=1;
x0=0; % x0,y0 ellipse centre coordinates
y0=0;
for t=0:0.01:2*pi;
if t < 0
x=x0+(abs(cos(t)).^(2/a)) * a*-1*(abs(cos(t)));
y=y0+(abs(sin(t)).^(2/b)) * b*-1*(abs(sin(t)));
end
if t == 0
x=x0+(abs(cos(t)).^(2/a)) * a*0*(abs(cos(t)));
y=y0+(abs(sin(t)).^(2/b)) * b*0*(abs(sin(t)));
end
if t > 0
x=x0+(abs(cos(t)).^(2/a)) * a*1*(abs(cos(t)));
y=y0+(abs(sin(t)).^(2/b)) * b*1*(abs(sin(t)));
end
figure(1)
plot(x,y)
grid on;
grid minor;
end
0 comentarios
Respuestas (1)
KSSV
el 22 de Mayo de 2017
clc ; clear all ;
n=2;
a=1;
b=1;
x0=0; % x0,y0 ellipse centre coordinates
y0=0;
figure(1)
hold on
for t=0:0.01:2*pi;
if t < 0
x=x0+(abs(cos(t)).^(2/a)) * a*-1*(abs(cos(t)));
y=y0+(abs(sin(t)).^(2/b)) * b*-1*(abs(sin(t)));
end
if t == 0
x=x0+(abs(cos(t)).^(2/a)) * a*0*(abs(cos(t)));
y=y0+(abs(sin(t)).^(2/b)) * b*0*(abs(sin(t)));
end
if t > 0
x=x0+(abs(cos(t)).^(2/a)) * a*1*(abs(cos(t)));
y=y0+(abs(sin(t)).^(2/b)) * b*1*(abs(sin(t)));
end
plot(x,y,'.r')
grid on;
grid minor;
end
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!