source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/lightspeed/randnorm.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 834 bytes
Line 
1function x = randnorm(n, m, S, V)
2% RANDNORM      Sample from multivariate normal.
3% RANDNORM(n,m) returns a matrix of n columns where each column is a sample
4% from a multivariate normal with mean m (a column vector) and unit variance.
5% RANDNORM(n,m,S) specifies the standard deviation, or more generally an
6% upper triangular Cholesky factor of the covariance matrix. 
7% This is the most efficient option.
8% RANDNORM(n,m,[],V) specifies the covariance matrix.
9%
10% Example:
11%   x = randnorm(5, zeros(3,1), [], eye(3));
12
13if nargin == 1
14  x = randn(1,n);
15  return;
16end
17[d,nm] = size(m);
18x = randn(d, n);
19if nargin > 2
20  if nargin == 4
21    if d == 1
22      S = sqrt(V);
23    else
24      S = chol(V);
25    end
26  end
27  if d == 1
28    x = S .* x;
29  else
30    x = S' * x;
31  end
32end
33if nm == 1
34  x = x + repmat(m, 1, n);
35else
36  x = x + m;
37end
Note: See TracBrowser for help on using the repository browser.