Loop animation with quiver plot

Hey guys. I am fairly new with matlab. Currently i am trying to animate the change of a velocity field in a fluid in time. The velocity field is dependent on depth (z) and distance (x). I would like to present the velocity field in a x/z coordinate system and by an animation show how it changes with time. I can plot the vector field by constant x with quiver(t,z,u,w). Is it possible to use a for-loop for the animation? I tried a lot of different solutions:
x=0
z=linspace(0, -h, 10);
t=linspace(0, 16*pi, 10);
for i=1:length(t)
for j=1:length(z)
u(j,i)=(pi*H)/T*(cosh(k)*(z(j)+h))/(sinh(k*h))*cos(omega*t(i)-k*x); %Particle velocity x direction
w(j,i)=-(pi*H)/T*(sinh(k)*(z(j)+h))/(sinh(k*h))*sin(omega*t(i)-k*x) %Particle velocity z direction
end
end
figure (4)
for t=linspace(0, 16*pi, 10);
for z=linspace(0, -h, 10);
quiver(x,z,u,w)
title('Velocity')
xlabel('Distance [m]') % x-axis label
ylabel('Depth [m]') % y-axis label
ylim([-h 10])
pause(1/60)
end
end

댓글 수: 5

CS Researcher
CS Researcher 2016년 5월 1일
Please share the relevant information? What is h, H, k, etc.
CS Researcher
CS Researcher 2016년 5월 1일
You can also look at 'drawnow' function
Emil Brandt
Emil Brandt 2016년 5월 1일
Sorry, the h, H and k are defined earlier on in the document. Those are water depth, wave height, and wavenumber, respectively.
KSSV
KSSV 2016년 5월 2일
many parameters are not defined.....give the values...it is easy to put it in a loop..
Emil Brandt
Emil Brandt 2016년 5월 3일
All values are defined in the document. I can easily plot the vector field components (u an w) in a time vs. depth diagram for a constant x (x=0) - as done in the attached file. The loop thing just seems not to be able to run the quiver plot in a x vs. depth for somehow.I want matlab to update the attached diagram by the time t, so that the vector field changes by time.

댓글을 달려면 로그인하십시오.

답변 (1개)

Alessandro Masullo
Alessandro Masullo 2016년 5월 3일

0 개 추천

Every time that you want to update the figure, you need to call the drawnow function. You won't probably be able to get a framerate of 60fps, but you may speed up the code by getting rid of the xlabel title functions.
If you want to generate a video, you may have a look at getframe.

카테고리

도움말 센터File Exchange에서 Animation에 대해 자세히 알아보기

질문:

2016년 5월 1일

답변:

2016년 5월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by