Home > atmlab > gridcreation > annealing > pick_random_freq.m

pick_random_freq

PURPOSE ^

PICK_RANDOM_FREQ Pick a random frequency.

SYNOPSIS ^

function i = pick_random_freq(s)

DESCRIPTION ^

 PICK_RANDOM_FREQ  Pick a random frequency.

 This picks a random element among those elements of the mask s for
 which s is true.

 The active frequencies are specified by a logical array s.

 FORMAT i = pick_random_freq(s)

 OUT  i   The chosen frequency.
 IN   s   The frequencies to choose from.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

pick_random_freq.m

SOURCE CODE ^

0001 % PICK_RANDOM_FREQ  Pick a random frequency.
0002 %
0003 % This picks a random element among those elements of the mask s for
0004 % which s is true.
0005 %
0006 % The active frequencies are specified by a logical array s.
0007 %
0008 % FORMAT i = pick_random_freq(s)
0009 %
0010 % OUT  i   The chosen frequency.
0011 % IN   s   The frequencies to choose from.
0012 
0013 % 2008-09-24 Created by Stefan Buehler.
0014 
0015 function i = pick_random_freq(s)
0016 
0017 % The active frequencies:
0018 f_active = find(s);
0019 
0020 % How many active frequencies?
0021 nactive  = length(f_active);
0022 
0023 % Choose random element in active.
0024 i_active = ceil(rand(1)*nactive);
0025 
0026 % Return index of this frequency.
0027 i = f_active(i_active);
0028

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005