Thread Subject: Question about animating in GUI timer function

Subject: Question about animating in GUI timer function

From: Kate J.

Date: 3 Mar, 2010 20:50:20

Message: 1 of 4

Hi! I am creating a gui (using GUIDE) that will display an animation that changes in response to the user’s mouse-click input. In order to update the animation at regular intervals, I have created a timer function that plots 1 updated frame of the animation each time it is called. There is only 1 axes on the gui, and its name is ArmAxes.

The problem I’m having is that the only way, so far, that I’ve been able to successfully animate within the timer function is to use the handles structure, as follows:

function animation_timer_fcn(hObject, events,figure_handle)

       …
       % update x & y values …
       …

       % plot 1 frame of animation
        plot(handles.ArmAxes,x,y);
        drawnow;

 
Although the animation displays correctly using this code, unfortunately the use of the handles structure in this timer function interferes with my (necessary) use of the handles structure elsewhere in my gui m-file, and it is causing many different bugs and data problems.

I’m trying to determine whether there is an alternative way to animate within the timer function, that doesn’t use the handles structure. Here are the options I’ve investigated:

       a) line_handle = handles.ArmAxes;
             set(line_handle,x,y);
             set(line_handle,'erasemode','xor');
             drawnow;


       b) line_handle = plot(x,y,'r-','LineWidth',2);
            set(line_handle,'erasemode','xor');
            drawnow;

             -- Both of these options eliminate all of the data problems I had been having when animating using the handles structure, BUT neither option produces any animation.


I have read in various places that using the plot( ) command isn’t efficient, and that using set(axes_handle,’erasemode’,’xor’) is much quicker and more efficient. However, so far, this code hasn’t worked to actually produce animation.

Any suggestions about how I can animate within my timer function, without using the handles structure (and, maybe, also avoiding the plot( ) command?)? Thanks!!

Subject: Question about animating in GUI timer function

From: Kate J.

Date: 8 Mar, 2010 21:50:24

Message: 2 of 4

Anyone have any experience with this problem? Thanks!

Subject: Question about animating in GUI timer function

From: Kate J.

Date: 11 Mar, 2010 16:26:21

Message: 3 of 4

Any ideas?

Subject: Question about animating in GUI timer function

From: tnsjoerd dobben

Date: 14 Mar, 2010 20:40:19

Message: 4 of 4

Hi Kate J.

I got more or less the same problem. I found this example on the net:

x = 0:.1:8;
y = 0:.1:8;
h = plot(x,y);

set(h,'YDataSource','y')
set(h,'XDataSource','x')

pause(2);
x = 8:.1:18;
y = 8:.1:18;
refreshdata

This is working in an single matlab file but I'm not able to make it work in GUIDE.
function StartMovie(handles, RenderXdata, RenderYdata)

sizeRenderXdata = size(RenderXdata);

XXData = 1;
YYData = 1;

h1 = plot(handles.axes1,XXData,YYData);
set(h1,'XDataSource','XXData');
set(h1,'YDataSource','YYData');

    for i=1:length(RenderXdata)
    % tic;
        for t=1:sizeRenderXdata(2)
            XXData = RenderXdata{i,t};
            YYData = RenderYdata{i,t};
            refreshdata
        end
    end
end

My GUI is having problems with this function. No response on my axes1 figure. What can be wrong??
I found something about the HandleVisibility in a forum but this did not work for me.

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