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 个)
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 个评论
Jeremy
2018-2-1
Rik
2018-2-2
In that case your callback doesn't automatically load the handles, so you'll have to do that yourself. I'll edit my answer.
Rik
2018-2-2
I don't understand why this error occurs. What version of Matlab are you using? And on what OS?
Rik
2018-2-2
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 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!