Hi Matt and Walter,
Firstly Matt, many apologies that you've run into this unintended behavior. Also, many thanks to you both for looking into this and flagging it up.
What has happened here? The short answer is that mapSolution was made an internal function in R2019a and replaced with varindex. Once we made mapSolution internal, we repurposed it in R2019b leading to the internal error you encountered. We will tidy up the error and add a note in the documentation pointing you to varindex
Matt's original code works with varindex
x=optimvar('x',{'x1','x2'},'LowerBound',[-100,-200]);
y=optimvar('y',1,3,'LowerBound',[0 0 0],'UpperBound',[+300,+400,+500]);
C.inequ=2*sum(y)+sum(x)<=1000;
C.equ=5*sum(x)==100;
prob=optimproblem('Constraints',C,'Objective',sum(x)+sum(y));
idx = varindex(prob);
Resulting in the output
idx =
struct with fields:
x: [1 2]
y: [3 4 5]
Also, varindex allows you to get the variable index by name, e.g.
idx = varindex(prob, 'y')
Resulting a double as the output
Matt, may I ask if you were aware of varindex? Also, is there anything in mapSolution that you are relying on that varindex doesn't provide?
Thanks again for flagging this and hope varindex helps!
Cheers,
Paul
Documentation for varindex:
Best Answer