Save the quiver plot as a video

Hello, I am trying to save the quiver plot as a .avi movie. I am including my code here:
hFig = figure;
subplot(1,2,1);
set(hFig, 'Position', [0 0 1000 1000]); % to define Figure Properties
stlgeometrie=stlread('gehause_Bmuster.stl');
geoplot(stlgeometrie);
axis([-200 200 -200 200 -200 200]);
view([0 0]);
hold on;
subplot(1,2,2);
set(hFig, 'Position', [0 0 1000 1000]); % to define Figure Properties
stlgeometrie=stlread('gehause_Bmuster.stl');
geoplot(stlgeometrie);
axis([-200 200 -200 200 -200 200]);
view([60 0]);
hold on;
for e = 1:length(range);
a=0.1;
subplot(1,2,1);
q1 = quiver3(x,y,z, a*mag_X(21,:)'.*cos(Ph_X(21,:)'+range(e)), a*mag_Y(21,:)'.*cos(Ph_Y(21,:)'+range(e)), a*mag_Z(21,:)'.*cos(Ph_Z(21,:)'+range(e)),0,'MarkerSize',3,'LineWidth',1.5,'MaxHeadSize',0.1);
subplot(1,2,2);
q2 = quiver3(x,y,z, a*mag_X(21,:)'.*cos(Ph_X(21,:)'+range(e)), a*mag_Y(21,:)'.*cos(Ph_Y(21,:)'+range(e)), a*mag_Z(21,:)'.*cos(Ph_Z(21,:)'+range(e)),0,'MarkerSize',3,'LineWidth',1.5,'MaxHeadSize',0.1);
M{e} = getframe;
Fz(e) = mag_Z(100,1)'.*cos(Ph_Z(100,1)'+range(e));
delete(q1);
delete(q2);
end
movie(cell2mat(M));
movie2avi(cell2mat(M),'MyMovie.avi','Compression','None');
When I use the following code, I can only see the video of second sub-plot and the video doesn't contain the video, but just a image of the second sub-plot. I just want to save the video which gets displayed because of the quiver command. I am also attaching my workspace variables with this query! Thank you in advance!

Answers (1)

M{e} = getframe(gcf);
Note: this will capture the entire figure, including window decorations. getframe() captures an axes or a figure, but you are creating multiple axes so you need to save the figure.

5 Comments

Thanks for the reply! I have used getframe(gcf), but it gives me the same output. The only thing different is that the video contains window decorations and the windows taskbar. The video doesn't contain the animation of the vectors. Instead, it creates a huge video file(150 Mb) of duration 8 secs containing just an image of the quiver plot. I guess the video contains only the last frame! Please help!
I suggest trying
M(e) = getframe(gcf);
and movie(M) and
movie2avi(M,'MyMovie.avi','Compression','None');
If nothing else these should be a little more efficient.
Also I recommend using an explicit 'fps' parameter even if you do want the default 15 fps -- it makes it clear to other people reading that you thought about the frame rate.
But movie2avi() is going away soon and it is recommended that you switch to VideoWriter, which might also cure the problem with last frame.
fps = 15; %to match movie2avi
v = VideoWriter('MyMovie.avi', 'Uncompressed AVI', 'FrameRate', fps);
open(v);
writeVideo(v, M);
close(v);
Thank you again for ur time. But the code still doesn't work. I am attaching the video file which I am getting after altering my code according to yours. You can try and run the code if you wish. The workspace variables can be found in the original attachment.
% Quiver vector field animation
hFig = figure;
set(hFig, 'Position', [0 0 2000 2000]); % to define Figure Properties
stlgeometrie=stlread('gehause_Bmuster.stl');
geoplot(stlgeometrie);
axis([-200 200 -200 200 -200 200]);
view([0 0]);
hold on;
for e = 1:length(range);
q1 = quiver3(x,y,z, a*mag_X(21,:)'.*cos(Ph_X(21,:)'+range(e)), a*mag_Y(21,:)'.*cos(Ph_Y(21,:)'+range(e)), a*mag_Z(21,:)'.*cos(Ph_Z(21,:)'+range(e)),0,'MarkerSize',3,'LineWidth',1.5,'MaxHeadSize',0.1);
M(e) = getframe(gca);
delete(q1);
end
fps = 15; %to match movie2avi
v = VideoWriter('MyMovie.avi', 'Uncompressed AVI', 'FrameRate', fps);
open(v);
writeVideo(v, M);
close(v);
I think it is time for me to go to bed (in a literal sense.)
Would be glad if you could get back to me tomorrow! :)

Sign in to comment.

Asked:

on 30 Nov 2015

Commented:

on 1 Dec 2015

Community Treasure Hunt

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

Start Hunting!