Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
mjhakeem

Posts: 1
Registered: 7/13/13
updating loop index
Posted: Jul 13, 2013 3:03 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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
Read updating loop index
mjhakeem
7/21/13
Read Re: updating loop index
Chris

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.