Home > wafo > wstats > wnormrnd.m

# wnormrnd

## PURPOSE

Random matrices from a Normal distribution.

## SYNOPSIS

R = wnormrnd(mu,v,varargin);

## DESCRIPTION

``` WNORMRND Random matrices from a Normal distribution.

CALL:  R = wnormrnd(mu,v,sz);

mu = mean       (Default 0)
v = variance   (Default 1)
sz = size(R)    (Default common size of mu and v)
sz can be a comma separated list or a vector
giving the size of R (see zeros for options).

Examples:
R  = wnormrnd(1,2,100,2,2);
R2 = wnormrnd(1,2,[100,3,2]);
wnormplot([R(:,:,1) R2(:,:,2)])

## CROSS-REFERENCE INFORMATION

This function calls:
 comnsize Check if all input arguments are either scalar or of common size. error Display message and abort function. nan Not-a-Number.
This function is called by:
 kdedemo1 Demonstrate the smoothing parameter impact on KDE mkernelrnd Random numbers from the Multivariate Kernel Function. wlognrnd Random matrices from a Lognormal distribution.

## SOURCE CODE

```001 function R = wnormrnd(mu,v,varargin);
002 %WNORMRND Random matrices from a Normal distribution.
003 %
004 % CALL:  R = wnormrnd(mu,v,sz);
005 %
006 %        mu = mean       (Default 0)
007 %         v = variance   (Default 1)
008 %        sz = size(R)    (Default common size of mu and v)
009 %             sz can be a comma separated list or a vector
010 %             giving the size of R (see zeros for options).
011 %
012 % Examples:
013 %   R  = wnormrnd(1,2,100,2,2);
014 %   R2 = wnormrnd(1,2,[100,3,2]);
015 %   wnormplot([R(:,:,1) R2(:,:,2)])
016 %
018
019 % tested on: matlab 5.3
020 % History:
021 % revised pab 23.10.2000
022 %  - added default mu,v
023 %  - added comnsize, nargchk
024 %  - added greater flexibility on the sizing of R
025 % by ??
026
027 error(nargchk(0,inf,nargin))
028 if nargin<1|isempty(mu),mu=0;end
029 if nargin<2|isempty(v), v=1;end
030
031 if nargin<3,
032   [errorcode mu v] = comnsize(mu,v);
033 else
034   [errorcode mu v] = comnsize(mu,v,zeros(varargin{:}));
035 end
036 if errorcode > 0
037     error('mu and v must be of common size or scalar.');
038 end
039 R=zeros(size(mu));
040 k=find(v>=0);
041 if any(k)
042   R(k)=randn(size(k)).*sqrt(v(k))+mu(k);
043 end
044 k1=find(v<0);
045 if any(k1)
046   tmp=NaN;
047   R(k1)=tmp(ones(size(k1)));
048 end
049```

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group

Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003