uploading variables to function
Ältere Kommentare anzeigen
hi everyone,
I am trying to do a project in matlab. I have three different script; main,constants,equastions. I am trying to call the script "constants "then call the function, all from the main (as it was instructed by the teacher) using this line of code :
constants;
[t,y] = ode15s(@(t,F)equations(t,F),tSpan,y0);
I keep getting these errors:
Unable to resolve the name con.E_t. Error in equations (line 12)
E_na = con.E_t*log(con.Nao/con.Nai);Error in main>@(t,F)equations(t,F) (line 129)
[t,y] = ode15s(@(t,F)equations(t,F),tSpan,y0);Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.Error in ode15s (line 150)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);Error in main (line 129)
[t,y] = ode15s(@(t,F)equations(t,F),tSpan,y0);
I think the problem is that my function equastions is no getting the variables which are in the constants script. how can i fix this?
Antworten (1)
Cris LaPierre
am 19 Dez. 2020
0 Stimmen
I think you are not considering variable scope. Functions do not share the same workspace as a script. See Base and Function Workspaces for more.
In this case, perhaps you just need to call your script inside your function?
1 Kommentar
yara abh
am 20 Dez. 2020
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!