Undefined variable error in nested function
显示 更早的评论
I keep getting the error message "Undefined function or variable 'z'." when I run:
z = [0.388039 0.264102 0.185497 4.66E-02 2.58E-02 7.68E-03]; %Smoke 1
D = 10; %mg
V = 25;
t = [1.0 3.0 5.0 14.0 18.0 24.0];
k1 = [0 1];
[kv,kval]=fmin(k1,D,t,z);
which calls the function below:
function [kv,kval]=fmin(k1,D,t,z)
[kv,kval]=fminsearch(@fminfunc,k1);
function f = fminfunc(kv)
sum=0;
for j=1:6
sum = sum + z(j) - (D/kv(2))*exp(-kv(1)*t(j));
end
f = sum^2;
return
return
and I get this output:
Undefined function or variable 'z'.
Error in hw4c_1>fminfunc (line 22)
sum = sum + z(j) - (D/kv(2))*exp(-kv(1)*t(j));
I'm not sure why the variable is undefined when I've already passed in the variables to the function. Please help
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!