Thread Subject: Complete redrawing with getframe?

Subject: Complete redrawing with getframe?

From: Christopher Hummersone

Date: 12 Jun, 2008 14:45:04

Message: 1 of 3

Hi,

I'm using 'getframe' within a for loop to capture changes in
a plot to a movie. The figure is actually a simple function
called 'waveplot' (which I downloaded from www.casabook.org):

function waveplot(x,gain)

% function waveplot(x,gain)

[r,c]=size(x);
if nargin==1
   gain=1;
end
if nargin==3
   for i=1:r,
      x(i,:)=x(i,:)/max(abs(x(i,:)));
   end
end
m=max(max(x));
hold on;
n=max(15*gain*x(r,:)/m+r*10);
for i=r:-1:1,
   xa=[1 1:c c 1];
   ya=[0 5*gain*x(i,:)/m+i*10 0 0];
   fill(xa,ya,'w');
end
hold off;
axis([1 c 0 n]);

% Code end

which basically plots rows of a matrix one above another (in
my case the outputs of a filterbank). The trouble is that
the very top row 'sticks' so that the results of previous
frames remain, but only on the top row. Of course,
standalone plotting does not produce this artefact. You can
see on the plot that the top row is still being plotted, but
remnants from previous frames remain stuck behind.

So my question is, is there a way to force a more
comprehensive redraw without closing and re-opening the
figure (which I tried and doesn't work)? The refresh
function does not solve the problem either (it is not strong
enough).

Subject: Complete redrawing with getframe?

From: Kelly Kearney

Date: 12 Jun, 2008 14:58:01

Message: 2 of 3

"Christopher Hummersone" <wheely_chairs@hotmail.com> wrote
in message <g2rcpg$3t6$1@fred.mathworks.com>...
> Hi,
>
> I'm using 'getframe' within a for loop to capture changes in
> a plot to a movie. ... The trouble is that
> the very top row 'sticks' so that the results of previous
> frames remain, but only on the top row. Of course,
> standalone plotting does not produce this artefact. You can
> see on the plot that the top row is still being plotted, but
> remnants from previous frames remain stuck behind.
>
> So my question is, is there a way to force a more
> comprehensive redraw without closing and re-opening the
> figure (which I tried and doesn't work)? The refresh
> function does not solve the problem either (it is not strong
> enough).

If I understand the issue correctly, adding a short pause
before issuing the getframe command will usually allow the
rendering to complete. Something like

f = figure;
for iframe = 1:nframe
    % Plotting commands here
    pause(1);
    fr{iframe} = getframe(gcf);
end

The length of the pause can be shorter for simpler plots,
and I find that 1 second is more than enough for most
slow-rendering plots.

-Kelly

Subject: Complete redrawing with getframe?

From: Christopher Hummersone

Date: 12 Jun, 2008 17:33:01

Message: 3 of 3

Hi Kelly,

Thanks for your reply. I didn't think it was an issue with
rendering taking too long but I tried your suggestion anyway
and alas it didn't work. But after a bit more poking I
managed to find a solution. The issue I believe is in the
hold status - the lines in the plot are held on the same
figure and the new data is just rendered over the top. So I
put the 'clf' (clear figure) command on the first line of
the code I included above and it worked :-) It's funny how
problems that seem complicated can be solved so simply!

Thanks again,

Chris

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com