Error in optimconstr() when used with single string vs array of string
显示 更早的评论
I'm working on MATLAB Version: 9.12.0.1884302 (R2022a) with Optimization Toolbox (9.3).
I have created 2 sets flight_name_set & Edges of type string
optimconstr gives the below error whenever the set is of single value but not on multiple values.
Error using optimconstr
Dimensions specifications must be a positive integer, string array, or a
cell array of character vectors.
For e.g
When Edges has 2 values Then there is no error.
flight_name_set =
1×5 string array
"Small-tt-1" "Medium-yy-2" "Medium-rr-3" "Jumbo-mm-4" "Jumbo-zz-5"
Edges =
1×2 string array
"W-Y" "S-Y"
optimconstr(Edges, flight_name_set, flight_name_set)
ans =
2×5×5 OptimizationConstraint array with properties:
IndexNames: {{1×2 cell} {1×5 cell} {1×5 cell}}
Variables: [1×1 struct] containing 0 OptimizationVariables
See constraint formulation with show.
but when Edges have 1 value there is error
flight_name_set =
1×5 string array
"Small-tt-1" "Medium-yy-2" "Medium-rr-3" "Jumbo-mm-4" "Jumbo-zz-5"
Edges =
"W-Y"
optimconstr(Edges, flight_name_set, flight_name_set)
Error using optimconstr
Dimensions specifications must be a positive integer, string array, or a cell array of character vectors.
With hit and trial I have to put a check on length and then use {Edges{:}} if there is only 1 value. Is there a way to use genralise statements?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!