MATLAB Answers

Why does matlab request me to define a for-loop indexing term?

Hi everyone,
I am trying to run the attached code, but matlab gives this error:
Undefined function or variable 'k'.
Error in SlurryCaseODE45Feb18>DifEq (line 212)
dcdt(1) = (1/V_Headspace) * (F * CSO2_in - F * c(1) )- ((((c(1)*R*T - ((c(3)*CH(k)^2)/(CH(k)^2 + KSO2*CH(k) + KSO2*KHSO3)) *
HSO2))/((1/kga) + (HSO2/(1 + ((DCa2 .* c(5))/(DSO2 .* c(3)))) * kLa_SO2))));
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in SlurryCaseODE45Feb18 (line 142)
Why does matlab request me to define k?
Please help.

  댓글 수: 0

로그인 to comment.


답변 수: 1

Walter Roberson 님의 답변 14 Feb 2019
 채택된 답변

Variables defined inside one workspace are not visible inside another workspace (the function) unless they are specifically passed in or otherwise imported.
However, you have
for k = 1: length(t)
Even if you were to pass k in specifically for use, then you would have the problem that you are overwriting t and Cv each iteration of k, so you would be throwing away all of the results except the last one.
You also use tv in several plot statements but you have not assigned anything to tv anywhere.

  댓글 수: 1

Thanks a lot Walter. The code now runs without errors.

로그인 to comment.

Translated by