%% Create Initial Point with Named Index Variables
% Create named index variables for a problem with various land types, potential crops, and plowing methods.

land = ["irr-good","irr-poor","dry-good","dry-poor"];
crops = ["wheat-lentil","wheat-corn","barley-chickpea","barley-lentil","wheat-onion","barley-onion"];
plow = ["tradition","mechanized"];
xcrop = optimvar('xcrop',land,crops,plow,'LowerBound',0);

% Set the initial point to a zero array of the correct size.

x0.xcrop = zeros(size(xcrop));

% Set the initial value to 3000 for the "wheat-onion" and "wheat-lentil" crops that are planted in any dry condition and are plowed traditionally.

[idxLand, idxCrop, idxPlough] = findindex(xcrop, ["dry-good","dry-poor"], ...
             ["wheat-onion","wheat-lentil"],"tradition");
x0.xcrop(idxLand,idxCrop,idxPlough) = 3000;

% Set the initial values for the following three points.
% Land      Crops           Method      Value
% dry-good  wheat-corn      mechanized  2000
% irr-poor  barley-onion    tradition   5000
% irr-good  barley-chickpea mechanized  3500

idx = findindex(xcrop,...
    ["dry-good","irr-poor","irr-good"],...
    ["wheat-corn","barley-onion","barley-chickpea"],...
    ["mechanized","tradition","mechanized"]);
x0.xcrop(idx) = [2000,5000,3500];

% Copyright 2012 The MathWorks, Inc.