How to change this code to 3D wave propagating animation?
Show older comments
When I run this code, I cannot get wave propagation animation. Can any professional give me a hand? Thanks very much.
clear all; clc;
A = 0.1; k = 1; w = 3; phi = 15;
x0 = 0; dx = 0.1; xf = 20; x = [x0:dx:xf];
t0 = 0; dt = 0.1; tf = 20; t = [t0:dt:tf];
path = 'G:\My Drive\Animation\'; frameRate2 = 840*630;
for i = 1:length(t)
y_tx(:,i) = 2*A.*cos(phi/2).*sin(k.*x(i)-w.*t+phi/2);
[X,Y] = meshgrid(y_tt(i,:));
end
videoWriter = VideoWriter([path, '3D constructive and destructive interference','.mp4']);
videoWriter.FrameRate = frameRate2;
open(videoWriter);
figure();
for i = 1: length(t)
surf(t,x,y_tt)
xlabel('Time'); ylabel('Space');
out = getframe(gcf); videoWriter.writeVideo(out);
end
videoWriter.close();
Accepted Answer
More Answers (0)
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!