How to make 3D-line plots (Sine Wave)?

13 visualizaciones (últimos 30 días)
Hamid Kilic
Hamid Kilic el 21 de Nov. de 2019
Comentada: Adam Danz el 21 de Nov. de 2019
Hi everybody, I am new to MATLAB and I need a help with this problem.
Plot a series of sine functions which are phase shifted by pi/10 and whose amplitudes are increased by 0.2. Final result is going to be like this. I tried bunch of methods but I couldn't get it. Thanks in advance.
sinewaves.png
  9 comentarios
Hamid Kilic
Hamid Kilic el 21 de Nov. de 2019
Thanks, you have given me so many useful tips.
Adam Danz
Adam Danz el 21 de Nov. de 2019
Glad I could help - I think you would have gotten there on your own which is a great learning process. Take time to understand each line of the answer that Star Strider gave to you so you can own the assignment and understand why it works.

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 21 de Nov. de 2019
With three small changes to your code, it works:
t = 0:0.01:5*pi;
z = 0:pi/12:2*pi;
phase = 0; % Initiliise Outside The Loop
a = 1:0.2:4; % Assign Outside The Loop
for k = 1:numel(a)
y(k,:) = a(k)*sin(t + phase);
phase = phase + pi/10;
% disp(y)
end
axes()
hold on
for i = 1:numel(z)
plot3(t,z(i)*ones(size(t)),y);
end
The changes are with respect to ‘phi’ and ‘phase’, and adding the ‘k’ loop counter and subscript.
My solution:
t = linspace(0, 4*pi);
a = (1:25);
sinmtx = 0.2*a(:).*sin(t + a(:)*pi/10);
figure
plot3(t, a(:)*ones(size(t)), sinmtx)
grid on
view(35,45)

Más respuestas (1)

Adam Danz
Adam Danz el 21 de Nov. de 2019
Editada: Adam Danz el 21 de Nov. de 2019
Since this seems like homework, my solution below shows how to produce the figure but you'll need to adapt it to comply with the requirements of the assignment.
t = 0:0.01:5*pi;
y = sin(t);
z = 0:pi/12:2*pi;
clf()
axes()
hold on
for i = 1:numel(z)
plot3(t,z(i)*ones(size(t)),y);
end
grid on
xlabel('t')
ylabel('o.5 pi') % Replace with ylabel(['0.5',char(960)]) for pi symbol
zlabel('sin(t)')
view(12.6, 27.6)

Categorías

Más información sobre Annotations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by