%% Obtain Problem Indices
% Create an optimization problem.

x = optimvar('x',3);
y = optimvar('y',3,3);
prob = optimproblem('Objective',x'*y*x);

% Convert the problem to a structure.

problem = prob2struct(prob);

% Obtain the linear indices in problem of all prob variables.

idx = varindex(prob);
disp(idx.x)
disp(idx.y)

% Obtain the y indices only.

idxy = varindex(prob,'y')

% Copyright 2018 The MathWorks, Inc.