Plotting help, function only giving one point
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Japoe25
el 27 de Abr. de 2015
Comentada: Star Strider
el 27 de Abr. de 2015
Hello friends,
I'm trying to recreate the image of a spiral staircase attached but I cant seem to get my code working. I just get a blank graph. I don't know how my loop is just giving me one point. Please help!
function z=my_staircase(a,b,h,n)
for t=0:2*pi*n
r=((a*b)*exp(-.04*t))/sqrt((b*cos(t)^2)+ (a*sin(t))^2);
x=r*cos(t);
y=r*sin(t);
z=(h*t)/(2*pi*n);
end
hold on
plot3(x,y,z)
xlabel('x(m)'); ylabel('y(m)');zlabel('z(m)');
grid on
0 comentarios
Respuesta aceptada
Star Strider
el 27 de Abr. de 2015
It’s giving you one point because that’s all you’re asking it to do.
A few tweaks, including subscripting ‘x’, ‘y’ and ‘z’ and all will be well:
function z = my_staircase(a,b,h,n)
tv = 0:2*pi*n;
for k1 = 1:length(tv)
t = tv(k1);
r=((a*b)*exp(-.04*t))/sqrt((b*cos(t)^2)+ (a*sin(t))^2);
x(k1)=r*cos(t);
y(k1)=r*sin(t);
z(k1)=(h*t)/(2*pi*n);
end
hold on
plot3(x,y,z)
xlabel('x(m)'); ylabel('y(m)');zlabel('z(m)');
grid on
view([-30 30])
end
Changing the view parameters (I added that) help too.
2 comentarios
Star Strider
el 27 de Abr. de 2015
I would change the ‘tv’ assignment to:
tv = linspace(0, 2*pi*n, 50*n);
That will smooth the plot.
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Performance en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!