Movie function via getframe(gcf) displays multi-axis figure incorrectly
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jonathan
am 24 Sep. 2014
Kommentiert: Jonathan
am 25 Sep. 2014
I have a problem where the movie() function creates an extra set of axes that I do not want around the outside of my figure, where no axes previously existed. More problematically, these axes push relevant info outside of the movie frame. Therefore I can't save a useful Avi file for presentations.
The code I'm using (minus irrelevant pieces) is:
for LOOP_PARAM=1:i_frame
%%%Data generating code%%%
%(define fw,fh,axh,axw etc... all my axis and figure sizes)
% Setup overall figure
f = figure;
set(f,'Units','inches','Position',[0 0 fw fh]);
set(f,'PaperPosition',[0 0 fw fh],'PaperSize',[fw fh]);
set(f,'Color','w','InvertHardcopy','off');
set(f,'Resize','off');%,'Toolbar','none');
set(f,'defaultAxesFontSize',16);%,'defaultaxesfontname','cmuserif');
% Setup axes within figure "f"
ax(1) = axes('Units',units,'position',[axl axb+0.5*axh+axvs axw2 axh]);
ax(2) = axes('Units',units,'position',[axl+1*(axw2+axhs) axb+0.5*axh+axvs axw1 axh]);
ax(3) = axes('Units',units,'position',[axl+1*(axw2+axhs) axb axw1 0.5*axh]);
%%%Section plotting Data%%%
%Capture movie frame
my_mov(LOOP_PARAM) = getframe(gcf);
end % frameloop
I can "fix" matlap playback of the movie if I play it via the following code from Matlab website, but that doesn't help with the key goal of getting this into an avi file I can use for presentations, as the cdata still has the axis around the entirety of figure f (that I don't want). I should note that I don't really know why this code works... axis are automatically 150 pixels wide perhaps?
% use 1st frame to get dimensions
[h, w, p] = size(my_mov(1).cdata);
hf = figure;
% resize figure based on frame's w x h, and place at (150, 150)
set(hf,'Position', [150 150 w h]);
axis off
% Place frames at bottom left
movie(hf,my_mov,1,0.5,[0 0 0 0]);
So, any thoughts on how I can get a movie file which just shows the three axes inside the main figure, which I can then save via mov2avi?
Many thanks for any help
PS. Running MatlabR2012b on MacOSX
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 24 Sep. 2014
Jonathan - have you verified that the avi output from movie2avi does in fact produce a video where the extra axes appears?
movie(M) plays the movie in matrix M once, using the current axes as the default target. If you want to play the movie in the figure instead of the axes, specify the figure handle (or gcf) as the first argument: movie(figure_handle,...). M must be an array of movie frames (usually from get frame).
By not providing a figure handle, then the movie is displayed in the current axes, and so you observe the extra set of axes around your frames. In the "fix" piece of code that you got from the MATLAB website
movie(hf,my_mov,1,0.5,[0 0 0 0]);
the movie is being run in the figure (given by hf) and not within the axes. (And this figure has been sized appropriately given the height and width of the frames.)
I think that your video will be fine (no extra axes) once you write the my_mov array to file using movie2avi and launch it outside of MATLAB.
Note that there is an alternative to this function which writes the frames immediately to file and so you avoid having to manage an array of frames. See VideoWriter for details.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!