Christianne - when you ask how to execute a while loop, what exactly do you mean? Do you mean that the while loop is not being entered (because the condition GAWtotal>GAWtarget is always false) or do you mean that the function never terminates because the code becomes stuck in the while loop?
A couple of things: the code calculates EBO1 and EBO3 as
EBO1(k+1)=(S(i)-k)*poisspdf(k,mday(i)*t(i));
EBO3(k+1)=(S(i)-k)*poisspdf(k,mday(i)*t(i));
yet the calculation of EBO2 is
EBO2(k+1)=poisspdf(k,mday(i)*t(i));
So there is no (S(i)-k) factor as there is in the other two. Is this intentional?
As well, on each iteration of the outer for loop, we see that the ith element of the S vector is reset as
while GAWtotal>GAWtarget
for i=1:size(mday,1);
S(i)=0;
% etc.
This means that we lose any of the accumulated "history" when we do
S(index)=S(index)+1;
Is this supposed to happen? If I pass in some dummy data (completely invalid) as
calcSfinal(randi(255,25,1),rand(25,1),randi(255,25,1),4, 12)
then the code becomes stuck in an infinite loop.
If I comment out the line
while GAWtotal>GAWtarget
for i=1:size(mday,1);
% S(i)=0;
% etc.
then the while loop does terminate after a certain number of iterations.
