trouble preventing movie frames overlapping

Hi!
I am using the following code to make a movie...
for j = 1:10
pcolor(longs,lats,qspeed(:,:,j)), shading flat
annotation('textbox',[0.24 0.54 0.2 0.1],'String',{datestr(date(j),12)},...
'FontSize',16,'LineStyle','none','Color',[1 1 1]);
F(j) = getframe;
end
movie(F,5)
...the problem I have is the textbox containing the date for each frame simply appears on top of the previous one. I need it to replace the previous one but cannot figure out the correct command. Any help greatly appreciated. Thanks

Answers (1)

You need to clear the other text. Use this function:
%=====================================================================
% Erases all lines from the current axes.
function ClearTextFromAxes()
try
axesHandlesToChildObjects = findobj(gca, 'Type', 'text');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
catch ME
errorMessage = sprintf('Error in function ClearTextFromAxes.\nError Message:\n%s', ME.message);
WarnUser(errorMessage);
end
return; % from ClearTextFromAxes
Just call ClearTextFromAxes before you call pcolor().
Or, you might want to call "cla" before you call pcolor since otherwise ALL the images you display become stored in the axes and your process will slow way down as you get to dozens and dozens of images.

2 Comments

Thanks for the quick response IA. I have tried this and it is still overwritting?? so Im still stuck
Any ideas?
Thanks
It should not. Set a breakpoint on the "if" statement. Then examine axesHandlesToChildObjects to see if it's empty. If it's empty, then you should have no text displayed. If it's not empty, watch the screen as it executes the delete statement and the text should disappear. Last resort is to call cla just before pcolor.

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Asked:

on 24 Nov 2012

Community Treasure Hunt

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

Start Hunting!