uploading variables to function

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?

回答(1 个)

Cris LaPierre
Cris LaPierre 2020-12-19

0 个投票

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?

类别

提问:

2020-12-19

评论:

2020-12-20

Community Treasure Hunt

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

Start Hunting!

Translated by