function Z=rvwait(X, r) % rvwait(X, r) Generates a column vector containing the sum of the first r % elements in each experiment of the random variable matrix X if r<=0 error('r <= 0') end M=size(X); if r>M(2) error('r is greater than experimental samples') end Z=zeros(M(1), 1); for i=1:M(1), Z(i)=sum(X(i,1:r)); end