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!