How to make a counter?

Hi, i'm trying to set up a counter such that after 3 days stocks will be replenished whenever the available stocks falls below 5. How do I do that?
%Preallocate the vector.
Available_Stock = zeros(1,31);
Available_Stock(1)=20;
for i= 1:numel(Available_Stock-1)
Available_Stock(i+1) = Available_Stock(i) - Stock_Sold(i);
%Intepretation: We do not have to add in new stocks as long as ordering amount is above 5.
if Available_Stock(i) > 5
Available_Stock(i+1) = Available_Stock(i) - Stock_Sold(i);
%Intepretation: Once ordering amount is at or below 5, we need to place an order.
else
while(Available_Stock(i) < 5 || Available_Stock(i) == 5)
counter = 0;
counter = counter +1;

2 Comments

What is (the badly-named) i? Is that the day number?
Indeed. Don't use i as a variable name, because it already used for the imaginary unit in MATLAB.

Sign in to comment.

Answers (0)

Asked:

W P
on 10 Oct 2014

Commented:

on 10 Oct 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!