Question about animating in GUI timer function

  • Follow


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!!
0
Reply Kate 3/3/2010 8:50:20 PM

Anyone have any experience with this problem? Thanks!
0
Reply Kate 3/8/2010 9:50:24 PM


Any ideas? 
0
Reply Kate 3/11/2010 4:26:21 PM

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. 
0
Reply sjoerdvanelp (1) 3/14/2010 8:40:19 PM

3 Replies
240 Views

(page loaded in 0.244 seconds)

Similiar Articles:













7/30/2012 3:39:11 PM


Reply: