RANDOMANGLE - choose a random angle (or cosine of angle if type is x) within allowed ranges angle = randomangle(nAng, type) nAng number of angles to generate type string identifying what range the random angle must be in angle resulting randomly chosen angle
0001 function angle = randomangle(nAng, type) 0002 0003 % RANDOMANGLE - choose a random angle (or cosine of angle if type is x) within 0004 % allowed ranges 0005 % 0006 % angle = randomangle(nAng, type) 0007 % 0008 % nAng number of angles to generate 0009 % type string identifying what range the random angle must be in 0010 % 0011 % angle resulting randomly chosen angle 0012 0013 % $Id: randomangle.m,v 1.3 2004/05/12 00:47:23 stuver Exp $ 0014 0015 % DETERMINE allowed range of the angle to be chosen 0016 % SET angle 0017 0018 angle = []; 0019 0020 if strcmp(lower(type), 'x') 0021 % Choose the cosine of the angle. range = (-1 1) 0022 angle = cos(rand(nAng, 1)*pi); 0023 elseif strcmp(lower(type), 'phi') 0024 % Choose the asimuth angle. range = (-pi pi) 0025 angle = (rand(nAng, 1)*2*pi)-pi; 0026 elseif strcmp(lower(type), 'psi') 0027 % Choose polarization angle. range = (0 2*pi) 0028 angle = rand(nAng, 1)*2*pi; 0029 else 0030 error('makelist -> randomangle: type must be ''x'', ''phi'' or ''psi''') 0031 end 0032 0033 return