-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharr2DEdge.m
28 lines (28 loc) · 834 Bytes
/
arr2DEdge.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
%
% Function to return the elements around the edge of a 2D array, in the
% CW direction: LL -> UL -> UR -> LR
%
% Automatically removes extraneous singletons above 2D.
% Returns empty if number of dimensions is not 2, or input is empty, or not
% an array.
% Returns the input array if it is 2D but one of the dimensions is of size
% 1.
%
% Copyright 2016 Elliot Sefton-Nash
function edge = arr2DEdge(arr)
if ~isempty(arr) && ismatrix(arr)
% Remove singletons
arr = squeeze(arr);
if ndims(arr) == 2 %#ok<ISMAT>
if any(size(arr) == 1)
edge = arr;
else
edge = [arr(end:-1:1,1)' arr(1,2:end), arr(2:end,end)', arr(end,end-1:-1:2)];
end
else
edge = [];
end
else
edge = [];
end
end