-
Notifications
You must be signed in to change notification settings - Fork 0
/
reflectEnds.m
45 lines (39 loc) · 1.1 KB
/
reflectEnds.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
function y = reflectEnds(x, N, dim)
%% reflectEnds
% Author: Erik Roberts
%
% Purpose: reflects data at start and end of data x by N along dim (default = 1)
%
% Usage: x = reflectEnds(x, N)
% x = reflectEnds(x, N, dim)
%
% Inputs (required):
% x: vector to augment
% N: amount to reflect on each end
%
% Inputs (optional):
% dim: dim to work along (default=1)
if isrow(x)
xStartReflect = fliplr(x(1, 2:N+1));
xEndReflect = fliplr(x(1, end-N:end-1));
y = [xStartReflect, x, xEndReflect];
elseif iscolumn(x)
xStartReflect = flipud(x(2:N+1, 1));
xEndReflect = flipud(x(end-N:end-1, 1));
y = [xStartReflect; x; xEndReflect];
else
dim = setDefault('dim', 1);
xDimLen = size(x,dim);
Index(1:ndims(x)) = {':'};
xStartReflectIndex = Index;
xStartReflectIndex{dim} = 2 : N+1;
xStartReflect = x(xStartReflectIndex{:});
y = cat(dim, xStartReflect, x);
clear xStartReflectIndex xStartReflect
xEndReflectIndex = Index;
xEndReflectIndex{dim} = xDimLen-N : xDimLen-1;
xEndReflect = x(xEndReflectIndex{:});
y = cat(dim, y, xEndReflect);
clear xEndReflectIndex xEndReflect
end
end