Undefined function or variable 'lb'.
3 views (last 30 days)
Show older comments
I have two function.The first 1 is afiqah and the second is MyCost.I wolud to call the data from afiqah to MyCost.
function[ub,lb,o]=afiqah()
lb=[57 66 22 22 17 8 32 33 36 33 18 41 80 115 105 70 57 42 17 17 12 10 11 20 36 37 20 30 35 15 20 2]
ub=[1170 1303 440 440 330 87 675 650 720 640 350 220 2200 2100 2100 1400 1139 837 405 220 240 269 220 730 710 400 600 661 150 105.5 330 29]
ak=[2759 7929 2053 7929 2053 1647 2180 3766 2525 4680 3938 4608 5261 4608 1300 817 1226 1340 2759 5507 9278 10815 6235 2759 2013 83 1250 725 313 313 13.97 2];
bk=[7.27 7.3 7.33 7.35 7.23 7.39 7.39 7.42 8.3 8.4 8.51 8.4 8.13 8.15 8.17 8.18 8.27 8.78 9.06 8.89 9.14 9.25 9.27 9.33 9.37 4.57 4.91 4.73 4.59 4.59 4.94 4.31];
o=ak.*bk;
end
function [FC] = MyCost(lb,ub,o)
afiqah;
randomArray=lb+(ub-lb).*rand(1,32);
intArray=floor(randomArray);
Pgen=sum(intArray);
if(11000<=Pgen)&&(Pgen<=16000)
FC=sum(intArray.*o);
end
end
The error is
MyCost(lb, ub, o)
Undefined function or variable 'lb'.
0 Comments
Answers (2)
madhan ravi
on 23 Nov 2018
Edited: madhan ravi
on 23 Nov 2018
lb=[57 66 22 22 17 8 32 33 36 33 18 41 80 115 105 70 57 42 17 17 12 10 11 20 36 37 20 30 35 15 20 2];
ub=[1170 1303 440 440 330 87 675 650 720 640 350 220 2200 2100 2100 1400 1139 837 405 220 240 269 220 730 710 400 600 661 150 105.5 330 29];
ak=[2759 7929 2053 7929 2053 1647 2180 3766 2525 4680 3938 4608 5261 4608 1300 817 1226 1340 2759 5507 9278 10815 6235 2759 2013 83 1250 725 313 313 13.97 2];
bk=[7.27 7.3 7.33 7.35 7.23 7.39 7.39 7.42 8.3 8.4 8.51 8.4 8.13 8.15 8.17 8.18 8.27 8.78 9.06 8.89 9.14 9.25 9.27 9.33 9.37 4.57 4.91 4.73 4.59 4.59 4.94 4.31];
o=ak.*bk;
FC = MyCost(lb,ub,o) %function call
function [FC] = MyCost(lb,ub,o) % function definition
randomArray=lb+(ub-lb).*rand(1,32);
intArray=floor(randomArray);
Pgen=sum(intArray);
if(11000<=Pgen)&&(Pgen<=16000)
FC=sum(intArray.*o);
end
end
Steven Lord
on 23 Nov 2018
You call your afiqah function with 0 output arguments inside your MyCost function. That means when the afiqah function finishes executing, it throws away the variables lb, ub, and o you defined inside it since the MyCost function never asked for those variables. Call afiqah with three outputs inside MyCost if you want the contents of the variables defined in it to be available to MyCost.
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!