Update Graph With Data Input
8 views (last 30 days)
Show older comments
Hi, I'm kind of new to matlab, but here is what I have. I have a series of functions that access data files and graph the intensity of light based on a user input wavelength. I just made it so that the input wavelength is controlled by a slider, but when I change the slider I do not know how to get the program to automatically regraph. One of the problems may be that when the wavelength is changed, the program basically will have to be re-exicuted because it will have to access a different file to graph based on the wavelength. Is there any way that I can make the program re-exicute when the 'waveLen' variable is changed? Or is there a way that I can make the program re-exicute after a certain time step, then if the value has been changed the graph will update? any help would be great.
0 Comments
Accepted Answer
Matt Fig
on 21 Jun 2011
You need to put the code which updates the plot in the slider callback. After this code, put a call to DRAWNOW.
More Answers (2)
Walter Roberson
on 21 Jun 2011
Is re-execution fast or slow?
When the user drags a slider, the callback for it will be called at irregular times (not defined in any documentation I've seen... possibly determined by time since last callback or possibly determined by number of mouse events that have been generated.) There is no method defined at the MATLAB level that can detect when the user stops (or pauses) dragging the slider.
These intermediate callbacks can be a problem if the calculation is not fast and cheap. You may wish to create your own mechanism to throttle the callbacks.
For example, you could create a timer, and have the slider callback just change the time the timer is to fire to (say) 5 seconds later. As the user drags generating multiple events, the timer firing will get progressively postponed. Eventually the user will pause for long enough and the timer will actually get to fire. The callback for the timer would have been set to run the procedure, using the then-current slider value to determine what to do.
0 Comments
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!