Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



updating loop index
Posted:
Jul 13, 2013 3:03 PM


Hello all,
i am doing a step in my code where i am generating a 5 vector random variable using (randperm) where number are from 1 to 3. then i am organizing them using (unique) and calculating how many times each number is repeated.
After that if a number is mentioned once i update the code to generate 4 vector random number or even more depending on how many one time a number appeared till i reach zero.
My problem is: every time a 5 vector random numbers are generated ??!!
is there a way to fix this; here is a part of the code:
clc clear NT=5; while(NT~=0) for i=1:NT g=randperm(3,1); x(:,i) = g; end x m=unique(x); n=hist(x,m); f=sum(n==1); % calculate if a number mentioned once NT=NTf fprintf('\n') end



