GUI stop button for ode45
1 view (last 30 days)
Show older comments
I am making a GUI where I am solving a system of ODE's using ode45, and I whish to have a stop button in my GUI. I have tried the following, without success. The value of handles.Flag is changed when I push the button, but the outputfunction doesn't seem to notice. Any suggestions?
The function where I call ode45 is given under:
function Start_Callback(hObject, eventdata, handles)
% hObject handle to Start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.Flag = false;
....
opts=odeset;
opts=odeset(opts,'RelTol',1e-6,'AbsTol',1e-9,'Stats','on','OutputFcn',...
@odeOut);
ode45(@odefun4,tspan,T2,opts);
Where odeOut is:
handles = guidata(gcbo);
...
if handles.Flag
status=true;
else
status = false;
end
guidata(gcbo, handles);
And the stop button function is:
function Stop_Callback(hObject, eventdata, handles)
% hObject handle to Stop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.Flag = true;
% save the changes to the structure
guidata(hObject,handles)
[EDITED, Jan Simon, code formatted]
0 Comments
Answers (1)
Jan
on 2 Mar 2012
You define "status" in the OutputFcn. But what happens with this value? Did you try to set a breakpoint in the "status=false" line to see what happens?
I do not find a description of the flag replied by the OutputFcn in the documentation. I do not expect, that it is sufficient for stopping the integration. But the Event function has a flag, which can be used for this reason.
See Also
Categories
Find more on Interactive Control and Callbacks 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!