State Change Callback on Slider Causing Error if Changed Too Fast

I have a jslider with a state change callback. When I drag the slider thumb, code is executed to calculate an area under a curve using trapz. The slider controls the end point of the integral interval. If I scroll through the slider slowly, or even at a reasonable pace, the code runs fine and there are no errors. But if I drag the slider quickly, I get an error with the trapz function that makes me think the code is caught in an unfinished state from the previous state change and is having a hard time keeping up with the slider value changing. I've thought about changing the callback to a mouse released or something that wouldn't change continuously, but I like the value given in real time as the slider is dragged. Any suggestions?

답변 (1개)

Rik
Rik 2018년 2월 1일
편집: Rik 2018년 2월 2일
Include a flag in your handles struct that returns the callback if there is already a callback being executed.
function your_slider_callback(hObject,eventdata)
handles=guidata(hObject);
if handles.isbusy
return
end
handles.isbusy=true;
guidata(hObject,handles)
%rest of your callback function%
handles.isbusy=false;
guidata(hObject,handles)
end

댓글 수: 6

I tried your suggestion and I get the following error:
"Not enough input arguments" on the last line of the following code
function stopSlider_Callback(hObject, eventdata, handles )
if handles.isbusy
In that case your callback doesn't automatically load the handles, so you'll have to do that yourself. I'll edit my answer.
Now I get the following error after the edit:
Undefined function or variable 'toDouble'.
Error in opaque/double (line 79)
dbl = toDouble(opaque_array(1));
Error in guidata (line 83)
if isscalar(h) && ishghandle(h)
Error in Moldy_v3/stopSlider_Callback (line 278)
handles = guidata(hObject);
I don't understand why this error occurs. What version of Matlab are you using? And on what OS?
Jeremy
Jeremy 2018년 2월 2일
편집: Jeremy 2018년 2월 2일
I think it has to do with the fact that I'm using a java javax.swing.JSlider. I found this article which discusses the toDouble function that is at the root of the error. I'm not sure why I didn't get any errors before the code you suggested, though. Most of what is discussed in the article is over my head.
What you can try is gcbf or even gcf as arguments to guidata, although I haven't worked with Java objects enough to understand your program structure.

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

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품

질문:

2018년 2월 1일

댓글:

Rik
2018년 2월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by