%% Create Optimization Variables Indexed by Strings
% Create an integer optimization variable vector named bolts that is indexed by the strings "brass", "stainless", and "galvanized". Use the indices of bolts to create an optimization expression, and experiment with creating bolts using character arrays or in a different orientation.
% Create bolts using strings in a row orientation.

bnames = ["brass","stainless","galvanized"];
bolts = optimvar('bolts',bnames,'Type','integer')

%
% Create an optimization expression using the string indices.

y = bolts("brass") + 2*bolts("stainless") + 4*bolts("galvanized")

%
% Use a cell array of character vectors instead of strings to get a variable with the same indices as before.

bnames = {'brass','stainless','galvanized'};
bolts = optimvar('bolts',bnames,'Type','integer')

%
% Use a column-oriented version of bnames, 3-by-1 instead of 1-by-3, and observe that bolts has that orientation as well.

bnames = ["brass";"stainless";"galvanized"];
bolts = optimvar('bolts',bnames,'Type','integer')

%
% Copyright 2012 The MathWorks, Inc.