%% Create Indexed Constraints in Loop
% Create indexed constraints and variables to represent the calories consumed in a diet. Each meal has a different calorie limit.

meals = ["breakfast","lunch","dinner"];
constr = optimconstr(meals);
foods = ["cereal","oatmeal","yogurt","peanut butter sandwich","pizza","hamburger",...
    "salad","steak","casserole","ice cream"];
diet = optimvar('diet',foods,meals,'LowerBound',0);
calories = [200,175,150,450,350,800,150,650,350,300]';
for i = 1:3
    constr(i) = diet(:,i)'*calories <= 250*i;
end

%
% Check the constraint for dinner.

show(constr("dinner"))

% Copyright 2012-2019 The MathWorks, Inc.