GUI stop button for ode45

1 view (last 30 days)
Per-Kristian
Per-Kristian on 2 Mar 2012
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]

Answers (1)

Jan
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.
  1 Comment
Per-Kristian
Per-Kristian on 2 Mar 2012
Sorry, this should be on top of the odeOut:
function status = odeOut(t,y,flag,varargin,data).
It says in the odeset documentation that the integration will stop if status=1. If I display the value of status in odeOut it is false all the time. If I press the stop button handles.Flag=true, but this doesn't seem to affect the handles.Flag inside the OutputFcn.

Sign in to comment.

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!