Update Graph With Data Input

조회 수: 10 (최근 30일)
Gar
Gar 2011년 6월 21일
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.

채택된 답변

Matt Fig
Matt Fig 2011년 6월 21일
You need to put the code which updates the plot in the slider callback. After this code, put a call to DRAWNOW.
  댓글 수: 1
Gar
Gar 2011년 6월 21일
Seemed to work, but I didn't include the drawnow function and it still seemed ok

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Sean de Wolski
Sean de Wolski 2011년 6월 21일
You want drawnow
doc drawnow;
for more info

Walter Roberson
Walter Roberson 2011년 6월 21일
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.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by