uploading variables to function
Afficher commentaires plus anciens
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?
Réponses (1)
Cris LaPierre
le 19 Déc 2020
0 votes
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 commentaire
yara abh
le 20 Déc 2020
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!