Why does matlab request me to define a for-loop indexing term?
1 次查看(过去 30 天)
显示 更早的评论
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)
[t,Cv]=ode45(@DifEq,tspan,c0,Options);
Why does matlab request me to define k?
Please help.
0 个评论
采纳的回答
Walter Roberson
2019-2-14
Variables defined inside one workspace are not visible inside another workspace (the function) unless they are specifically passed in or otherwise imported.
See paramfun
However, you have
for k = 1: length(t)
[t,Cv]=ode45(@DifEq,tspan,c0,Options);
end
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!