Why is 'handles.edit12' not working? (GUI)
1 次查看(过去 30 天)
显示 更早的评论
Hi, I'm working on a GUI designed in GUIDE, I have two of them which are similar, one is working and the other is not, I'm getting the following error whenever I run it, this is the part of the code which has the error line:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
global tf Q1_0 Q2_0 S1_0 S2_0 I0 X1_0 X2_0 X3_0
tspan = [0; tf];
x0 = [Q1_0; Q2_0; S1_0; S2_0;I0; X1_0;X2_0; X3_0];
[t,x] = ode45(@fun,tspan,x0);
out1=[t,x]
axes(handles.axes1);
plot(t,x(:,1));
grid on
Insu=x(:,5)/10;
axes(handles.axes2);
plot(t,Insu);
grid on
function f= fun(t,x,handles)
F01= 0.0097;
EGP0= 0.0161;
k12=0.066;
DG=0;
AG=0.8;
tmaxG=40;
VG= 0.16;
tmaxI=55;
Ke=0.138;
VI=0.12;
Ka1=0.006;
Ka2=0.06;
Ka3=0.03;
Kb1= 51.2e-4*Ka1;
Kb2= 8.2e-4*Ka2;
Kb3= 520e-4*Ka3;
% Aux. Functions
G=x(1)/VG;
if G>=4.5
F01_C=F01;
else
F01_C=F01*G/4.5;
end
if G>=9
FR=0.003*(G-9)*VG;
else
FR=0;
end
UI=x(4)/tmaxI;
UG=(DG*AG*t*exp(-t/tmaxG))/(tmaxG)^2;
newData1=importdata(get(handles.edit12,'String')); % LINE 284
% newData1=importdata('datosnoembarazo.mat');
% uu1=getfield('newData1','insudia1');
uu1=getfield(newData1,get(handles.edit14,'String'));
ufun = @(t) interp1(1:length(uu1), uu1, t, 'nearest', 0);
f = [
-((F01_C/VG*G)*x(1))+ x(6)*x(1) + k12*x(2) - FR + UG + EGP0*(1-x(8)); %(1)
x(6)*x(1)-(k12+x(7))*x(2); %(2)
ufun(t)-(x(3)/tmaxI); %(3)
(x(3)/tmaxI)-(x(4)/tmaxI); %(4)
UI/VI - Ke*x(5); %(5)
-Ka1*x(6)+ Kb1*x(5); %(6)
-Ka2*x(7)+ Kb2*x(5); %(7)
-Ka3*x(8)+ Kb3*x(5); %(8)
];
The error I get:
Error using Extendido_Hovorka>fun
(line 284)
Not enough input arguments.
I have tried it with the commented lines, where I choose .mat files to work with and the code works but since this is a GUI I need to let the user choose which file/vector he wants to work with, so do you know why is it not working? The other code I talked about is basically the same, just that the equations are different from this one, thanks
0 个评论
采纳的回答
Walter Roberson
2015-12-1
Note several efficiency changes made.
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
global tf Q1_0 Q2_0 S1_0 S2_0 I0 X1_0 X2_0 X3_0
%do this outside of the objective function. If the data changes during the
%objective function then your ODE would become inconsistent, so it is safer
%and faster to do it before the objective function
newData1=importdata( get(handles.edit12,'String') );
uu1 = getfield(newData1,get(handles.edit14,'String'));
ufun = @(t) interp1(1:length(uu1), uu1, t, 'nearest', 0);
tspan = [0; tf];
x0 = [Q1_0; Q2_0; S1_0; S2_0;I0; X1_0;X2_0; X3_0];
%the objective function needs ufun passed in
[t,x] = ode45(@(t,x) fun(t, x, ufun), tspan, x0);
out1=[t,x]
axes(handles.axes1);
plot(t,x(:,1));
grid on
Insu=x(:,5)/10;
axes(handles.axes2);
plot(t,Insu);
grid on
function f= fun(t, x, ufun)
F01= 0.0097;
EGP0= 0.0161;
k12=0.066;
DG=0;
AG=0.8;
tmaxG=40;
VG= 0.16;
tmaxI=55;
Ke=0.138;
VI=0.12;
Ka1=0.006;
Ka2=0.06;
Ka3=0.03;
Kb1= 51.2e-4*Ka1;
Kb2= 8.2e-4*Ka2;
Kb3= 520e-4*Ka3;
% Aux. Functions
G=x(1)/VG;
if G>=4.5
F01_C=F01;
else
F01_C=F01*G/4.5;
end
if G>=9
FR=0.003*(G-9)*VG;
else
FR=0;
end
UI=x(4)/tmaxI;
UG=(DG*AG*t*exp(-t/tmaxG))/(tmaxG)^2;
%we no longer read in the data here and build ufun here; ufun is
%now passed in
f = [
-((F01_C/VG*G)*x(1))+ x(6)*x(1) + k12*x(2) - FR + UG + EGP0*(1-x(8)); %(1)
x(6)*x(1)-(k12+x(7))*x(2); %(2)
ufun(t)-(x(3)/tmaxI); %(3)
(x(3)/tmaxI)-(x(4)/tmaxI); %(4)
UI/VI - Ke*x(5); %(5)
-Ka1*x(6)+ Kb1*x(5); %(6)
-Ka2*x(7)+ Kb2*x(5); %(7)
-Ka3*x(8)+ Kb3*x(5); %(8)
];
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!