Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: updating loop index
Replies: 1   Last Post: Jul 21, 2013 3:18 PM

 Messages: [ Previous | Next ]
 mjhakeem Posts: 1 Registered: 7/13/13
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=NT-f
fprintf('--\n')
end

Date Subject Author
7/13/13 mjhakeem
7/21/13 Chris