Error in setting UpperBound in optimvar
조회 수: 12 (최근 30일)
이전 댓글 표시
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 24x4 table containing numerical values. What is the problem here?
댓글 수: 4
채택된 답변
Walter Roberson
2018년 9월 28일
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.
댓글 수: 2
Walter Roberson
2018년 9월 29일
Why do those items turn into cell arrays? Are you doing a readtable() from a file? If so then you probably need to adjust the readtable(), perhaps in connection with DetectImportOptions if you have a new enough version for that.
I use the term "table object" to emphasize that I am referring to the MATLAB "table" data type, not just data that happens to be arranged in a 2D presentation and therefore might be commonly called a "table".
Likewise, I refer to "string object" to emphasize when I am referring to the MATLAB "string" data type rather than referring to other things that might commonly be called strings. Historically, character row vectors were commonly called strings, which you can see in function names such as strcmp() ["string compare"] and cellstr() ["cell string"]
Table objects are a structured data type. Within each column of a table object, all values must be the same data type, but the different columns can be different data types. If it is necessary to have a mix of data types within one column, then the entries in the column must be stored in a cell array. For example if there were a text header that was stored along with numeric values then because the text would be a character vector or string object scalar, a different data type than the numeric values, the column would have to be represented as a cell array. But if the creation of the table object were to be such that the character vector or string scalar never got there, then all of the entries in the column could be numeric and cell2mat() would not be needed.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!