"Not enought input arguments" ode45 error

1 次查看(过去 30 天)
Hello, everyone,
I'm working on a code for a GUI in Matlab where I use a subfunction that uses ode45, the problem is that it sends me this error:
Error using Prueba_con_Bergman>f (line 292)
Not enough input arguments.
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets
args{1} to yp0.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0,
f0, odeArgs, odeFcn, ...
Error in Prueba_con_Bergman>pushbutton1_Callback
(line 264)
[t,x] = ode45(@f,tspan,x0);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Prueba_con_Bergman (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)Prueba_con_Bergman('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
I'm saving the numbers given to the GUI into some variables, where it is also converted into double. This is the part that executes the ode 45:
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
tf= str2double(get(handles.edit6,'String'))
G0= str2double(get(handles.edit7,'String'))
X0= str2double(get(handles.edit8,'String'))
I0= str2double(get(handles.edit10,'String'))
% function innerdiabetic
tspan = [0; tf];
x0 = [G0; X0; I0]; %Falta modificar D
[t,x] = ode45(@f,tspan,x0);
axes(handles.axes2); %Grafica glucosa
plot(t,x(:,1));
grid on
axes(handles.axes3); %Grafica insulina remota
plot(t,x(:,2));
grid on
axes(handles.axes4); %Grafica insulina
plot(t,x(:,3));
grid on
function dxdt = f(t,x,handles)
p1= str2double(get(handles.edit1,'String')) %THIS IS LINE 292
p2= str2double(get(handles.edit2,'String'))
p3= str2double(get(handles.edit3,'String'))
n= str2double(get(handles.edit4,'String'))
Gb= str2double(get(handles.edit11,'String'))
dxdt = [ (p1 - x(2))*x(1) - ((p1)*Gb); %dG(t)/dt
(p2*x(2) + p3*x(3));
(n*x(3))
];
I have no problem with the first variables, it's just until line 292 that starts the problem, I tried it with constants instead of variables and it works. What it wrong with the code?
Thanks

回答(1 个)

Steven Lord
Steven Lord 2015-8-3
You aren't passing the handles structure into your ODE function. But I would avoid doing that anyway; as written, if you DID pass the handles structure in you'd be querying the graphics objects for its property values every time the ODE solver called your function. That's going to be slow, and could allow the user to modify the problem while you're trying to solve it.
Instead I recommend retrieving the property values from the graphics objects BEFORE calling the ODE solver and passing the retrieved values in as additional parameters. The documentation for the ODE solvers includes a link to a documentation page that describes how to pass additional parameters into your ODE function.

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by