RandVectorPURPOSESelects and element from a discrete probability distribution.
SYNOPSISfunction i=RandVector(v)
DESCRIPTIONSelects and element from a discrete probability distribution. Returns an element at random using the (absolute) values of the input vector as selection weights. CROSS-REFERENCE INFORMATIONThis function calls:
SOURCE CODE0001 function i=RandVector(v) 0002 % Selects and element from a discrete probability distribution. 0003 % 0004 % Returns an element at random using the (absolute) values of the input 0005 % vector as selection weights. 0006 0007 va=abs(v); 0008 0009 r=rand*sum(va); 0010 i=1; 0011 s=va(i); 0012 while s<r 0013 i=i+1; 0014 s=s+va(i); 0015 end |