Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Slider callback plot flicker problem...

Status
Not open for further replies.

Jacc

Automotive
Oct 22, 2002
142
Hey hey hey!

Whenever I want to analyze a mathematical function with multiple parameters I make a quick GUI in Matlab. I assign sliders to each of the parameters I want to change and their callback functions replot the function with the new value. Here is a very simple example:


Main Program
-------------------------------------------------------
a=4;
fighandle=figure(1)
slidehandle = uicontrol(fighandle,'Style','Slider')
set (slidehandle,'Value',4,'Min',1,'Max',20,'Callback','UIcall_2(slidehandle)')
set (slidehandle,'SliderStep',[0.1 1])
x=1:100;
y=x.^2+a.*x;
plot(x,y,'x')
----------------------------------------------------------



Callback Function
----------------------------------------------------------
function UIcall(slidehandle)
a=get(slidehandle,'Value')
x=1:100;
y=x.^2+a.*x;
plot(x,y,'x')
----------------------------------------------------------


Nice isn't it?
Well, this is my problem:
When I klick and hold on one of the slider arrows to make it sweep through it's range the whole figure flickers!
Sure you can see the curve changing shape and all that but my current project includes a bunch of lines and A LOT of sweeping sliders through their ranges, full screen of course, and this flickering is a big problem!
I'm not epileptic but if I was I would have seized for good by now!

Just a few minutes ago after I had been messing with it the damned thing started to move smooth as silk without a trace of flickering! Just the lines changing supersmooth on the screen but ofcourse next time I hit run it was back to hysteric flickering...

What's causing this and how can I make it go away?

Is it a figure property issue, NextPlot or something?

Or should I plot using line instead?

Or perhaps plot using set(line_handle,'XData',x,'YData',y)?

Thank you for reading this far and good night!



 
Replies continue below

Recommended for you

Well since nobody had the opportunity to answer me I just have to do it myself...

Hey Jacc

Very good question! It has a very simple solution. Set the figure property 'DoubleBuffer' to 'on'. I found this on another Matlab forum.

Although your own suggestions won't help the flicker it will certainly speed things up. I did a simple for loop with different plot methods in it and timed the loop with tic toc.

The plot command calls another 45 lbs of m-files before it's done, amazing that it doesn't take longer. I found out by using the debug function 'step-into'.

The line command is about a hundred times faster.

Using set(line_handle,'XData',x,'YData',y) is super duper fast! Something like 10 000 times faster than using plot! You might have to use the drawnow command, though.

Here is the link to the other forum:

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor