State Change Callback on Slider Causing Error if Changed Too Fast
Mostra commenti meno recenti
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?
Risposte (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 Commenti
Jeremy
il 1 Feb 2018
Rik
il 2 Feb 2018
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
il 2 Feb 2018
I don't understand why this error occurs. What version of Matlab are you using? And on what OS?
Rik
il 2 Feb 2018
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.
Categorie
Scopri di più su Numerical Integration and Differentiation in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!