File: RandLim.m

package info (click to toggle)
psychtoolbox-3 3.0.9%2Bsvn2579.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 63,408 kB
  • sloc: ansic: 73,310; cpp: 11,139; objc: 3,129; sh: 1,669; python: 382; php: 272; makefile: 172; java: 113
file content (24 lines) | stat: -rw-r--r-- 845 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function out = RandLim(n,lower,upper)
% returns pseudo-random values drawn from a uniform distribution with lower
% and upper limits LOWER and UPPER.
% LOWER and UPPER can also be matrices of the same shape as rand(N) would
% create
%
% N is a vector indicating the dimensions of the output:
%   N = [3]      creates a    3x3 matrix
%   N = [1,3]    creates a    1x3 matrix
%   N = [17,1,3] creates a 17x1x3 matrix
%
% LOWER and UPPER can be any number

% DN 2008-07-21 Wrote it
% DN 2008-09-19 Support for vector lower and upper limits

error(nargchk(3, 3, nargin, 'struct'))

r = rand(n);
if (~isscalar(lower) && any(size(lower)~=size(r))) || (~isscalar(upper) && any(size(upper)~=size(r)))
    error('LOWER and UPPER must each be scalar or have the same shape as rand(N)')
else
    out = lower + r.*(upper-lower);
end