-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsp_rep_values.m
53 lines (50 loc) · 1.34 KB
/
sp_rep_values.m
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
50
51
52
53
function values = sp_rep_values(data_array, num_reps)
% function values = sp_rep_values(data_array, num_reps)
%
% Creates a vector of values from the given inputs:
% Element [i] in data_array is repeated num_reps[i] times, then concatenated to values
%
% INPUTS:
% data_array: [array] of N values
% num_reps : [array] indicating how many times the values in data_array should be repeated
%
% OUTPUT:
% values : [array][sum(num_reps) x 1] with repeated values as specified
%
% For example:
% values = sp_rep_values([1 2 3 4 5], [2 3 1 0 4])
%
% values =
%
% 1
% 1
% 2
% 2
% 2
% 3
% 5
% 5
% 5
% 5
%
% Sagi Perel, 05/2011
if(nargin ~= 2)
error('sp_rep_values: wrong number of input arguments provided');
end
if(~isvector(data_array))
error('sp_rep_values: data_array should be a non-empty vector');
end
if(~isvector(num_reps))
error('sp_rep_values: num_reps should be a non-empty vector');
end
N = length(data_array);
M = length(num_reps);
if(N ~= M)
error('sp_rep_values: data_array and num_reps should have the same size');
end
cumsum_reps = cumsum(num_reps);
values = nan(sum(num_reps),1);
values(1:num_reps(1)) = data_array(1);
for i=2:N
values( cumsum_reps(i-1)+1 : cumsum_reps(i) ) = data_array(i);
end