How to make 3D-line plots (Sine Wave)?
59 次查看(过去 30 天)
显示 更早的评论
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.
9 个评论
Adam Danz
2019-11-21
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.
采纳的回答
Star Strider
2019-11-21
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)
0 个评论
更多回答(1 个)
Adam Danz
2019-11-21
编辑:Adam Danz
2019-11-21
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)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!