error using ode45 in gui

8 visualizzazioni (ultimi 30 giorni)
pawan kumar
pawan kumar il 28 Set 2011
while debugging code for flat-fire using ode45 it gives error
err0r:-
??? Error while evaluating uicontrol Callback
??? Error using ==> feval
Undefined function or method 'fnflatfiredragwind' for input
arguments of type 'double'.
Error in ==> guitry>togglebutton1_Callback at 187
[t,c,te,ze,ie] =
ode45('fnflatfiredragwind',tspan,c0,options,w1,w2,w3,k);
??? Error while evaluating uicontrol Callback
*
here is the function defined in toggle button
function togglebutton1_Callback(hObject, eventdata, handles)
v0 = str2num(get(handles.edit1,'string'));
theta = str2num(get(handles.edit2,'string'));
theta = theta*pi/180;
w1 = str2num(get(handles.edit3,'string'));
w2 = str2num(get(handles.edit4,'string'));
w3 = str2num(get(handles.edit5,'string'));
k = str2num(get(handles.edit6,'string'));
set(handles.text1,'string',result);
c0 = [0;v0*cos(theta);0;v0*sin(theta);0;0];
options = odeset('events','on');
tspan = [0 10];
[t,c,te,ze,ie] = ode45('fnflatfiredragwind',tspan,c0,options,w1,w2,w3,k);
what is this error ????????????????
please help me for this
thanks
pawan kumar
  1 Commento
Jan
Jan il 28 Set 2011
Please use proper code formatting to improve the readability. Follow the "Markup help" link to learn the details.

Accedi per commentare.

Risposte (4)

Grzegorz Knor
Grzegorz Knor il 28 Set 2011
Replace line:
[t,c,te,ze,ie] = ode45('fnflatfiredragwind',tspan,c0,options,w1,w2,w3,k);
with:
[t,c,te,ze,ie] = ode45(@fnflatfiredragwind,tspan,c0,options,w1,w2,w3,k);
  5 Commenti
pawan kumar
pawan kumar il 29 Set 2011
i used @fnflatfiredragwind in place of fnflatfiredragwind but now the error is different. now it is not accepting the variable which i am passing through ode45 argument to the function file.
this problem comes only when i am using push-button to run the code. in simple(not from gui).it gives no error.
error :-
??? Input argument "k" is undefined.
Error in ==> guitry>fnflatfiredragwind at 180
value = [c(2); -k*(c(2)-w1)^2; c(4); (-k*(c(2)-w1)*(c(4)-w2))-g;
c(6); -k*(c(2)-w1)*(c(6)-w3)];
Error in ==> odearguments at 109
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs,
odeFcn, ...
Error in ==> guitry>togglebutton1_Callback at 210
[t,c,te,ze,ie] =
ode45(@fnflatfiredragwind,tspan,c0,options,w1,w2,w3,k);
function file is
function [value,isterminal,dircn] = fnflatfiredragwind(t,c,flag,w1,w2,w3)
g = 9.8;
% c(1) = x; c(2) = dx/dt = vx ; c(3) = y ; c(4) = dy/dt = vy ; c(5) = w
% c(6) = dc/dt = vz
if nargin<7 || isempty(flag)
value = [c(2); -k*(c(2)-w1)^2; c(4); (-k*(c(2)-w1)*(c(4)-w2))-g; c(6); -k*(c(2)-w1)*(c(6)-w3)];
else
switch flag
case 'events'
value = c(3);
isterminal = 1;
dircn = 0;
otherwise
error('function not programmed for this event');
end
end
Grzegorz Knor
Grzegorz Knor il 29 Set 2011
You don't pass the k argument to the function. Please correct this line:
function [value,isterminal,dircn] = fnflatfiredragwind(t,c,flag,w1,w2,w3,k)

Accedi per commentare.


Jan
Jan il 28 Set 2011
The error means, that the file "fnflatfiredragwind.m" cannot be found in the Matlab path and the current directory (see cd). Where is it? Is it a local subfunction? Then Grzegorz's idea of using a function handle might help.

Walter Roberson
Walter Roberson il 29 Set 2011
Convert
[t,c,te,ze,ie] =
ode45(@fnflatfiredragwind,tspan,c0,options,w1,w2,w3,k);
to
[t,c,te,ze,ie] =
ode45(@(t) fnflatfiredragwind(t,w1,w2,w3,k),tspan,c0,options);
convert
function [value,isterminal,dircn] = fnflatfiredragwind(t,c,flag,w1,w2,w3)
to
function [value,isterminal,dircn] = fnflatfiredragwind(t,c,flag,w1,w2,w3,k)
  2 Commenti
pawan kumar
pawan kumar il 4 Ott 2011
now the error is
??? Error using ==> guitry>@(t)fnflatfiredragwind(t,w1,w2,w3,k)
Too many input arguments.
Error in ==> odearguments at 109
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in ==> rr>togglebutton1_Callback at 257
[t,c,te,ze,ie] = ode45(@(t) fnflatfiredragwind(w1,w2,w3,k),tspan,c0,options);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> rr at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)rr('togglebutton1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
please reply me a efficient method so that i can make gui of my programme
Walter Roberson
Walter Roberson il 4 Ott 2011
Correction:
[t,c,te,ze,ie] =
ode45(@(t) fnflatfiredragwind(t,w1,w2,w3,k),tspan,c0,options);
should be
[t,c,te,ze,ie] =
ode45(@(t,c) fnflatfiredragwind(t,c,[],w1,w2,w3,k),tspan,c0,options);

Accedi per commentare.


pawan kumar
pawan kumar il 10 Ott 2011
i tried the above method but still it was giving error but now i got the mistake actually the programme is running using the same code [t,c,te,ze,ie] = ode45('fnflatfiredragwind',tspan,c0,options,w1,w2,w3,k);
but previously the mistake which i was doing is i was displaying sth between button function and variable
function togglebutton1_Callback(hObject, eventdata, handles)
clc
clear all
close all
disp(' ')
v0 = str2num(get(handles.edit1,'string'));
when i remove that the programme executed without error
function togglebutton1_Callback(hObject, eventdata, handles)
thanks
v0 = str2num(get(handles.edit1,'string'));
  2 Commenti
Walter Roberson
Walter Roberson il 10 Ott 2011
Any program that has "clear all" in it is 99%+ likely to be broken.
Walter Roberson
Walter Roberson il 10 Ott 2011
Please point me to a reference page or user guide page that shows passing additional variables by placing them after the "options" structure in an ode*() call. I have been unable to find such a page myself; all I have been able to find so far is pages that say specifically that YOU CANNOT DO THAT.

Accedi per commentare.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by