MATLAB: Error in setting UpperBound in optimvar

MATLABmatlab exampleoptimvar

I'm trying to implement this example:
when I get to this line:
power = optimvar('power',nHours,plants,'LowerBound',0,'UpperBound',maxGenConst);
I get the following error message: " _Error using optimvar (line 118) Error setting property 'UpperBound' of class 'optim.problemdef.OptimizationVariable': Value must be numeric."
The UpperBound variable maxGenConst is a 24×4 table containing numerical values. What is the problem here?

Best Answer

plantProps is a table() object, but
MaxGenerationLevel = plantProps{5,:};
which extracts row 5 of plantProps table into numeric form.
Then,
maxGenConst = repmat(MaxGenerationLevel,nHours,1);
replicates that numeric row into multiple rows, still giving you numeric form.
So by the time you are at
power = optimvar('power',nHours,plants,'LowerBound',0,'UpperBound',maxGenConst);
maxGenConst is numeric, not a table object.