-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrand_col.m
More file actions
50 lines (42 loc) · 1.32 KB
/
rand_col.m
File metadata and controls
50 lines (42 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function [retcol] = rand_col(rows, start, stop, step)
%RAND_COL Generate a column of random numbers.
%
% Random numbers will be uniform distribution (if step = 0)
% or choice from discrete values (if step > 0).
%
% Arguments:
% rows -- number of rows (random numbers) in column
% start -- minimum value of random numbers (inclusive)
% stop -- maximum value of random numbers (inclusive)
% step -- if specified, numbers will be of form start + k*step <= stop
% (where k is a positive integer)
if rows < 1
error('UWMadison:MoodleDataset:argValue', ...
'rows must be > 0', ...
rows)
end
if start > stop
error('UWMadison:MoodleDataset:argValue', ...
'start must be > stop', ...
start, ...
stop)
elseif start == stop
retcol = start * ones([rows, 1]);
return
end
if ~exist('step', 'var')
% Not specified. Assume uniform distribution.
step = 0;
end
if step < 0
error('UWMadison:MoodleDataset:argValue', ...
'step must be >= 0', ...
step)
end
if step == 0
retcol = start + ((stop - start) * rand([rows, 1]));
else
numsteps = floor((stop - start) / step);
retcol = start + (step * randi(numsteps, [rows, 1]));
end
end