-
Notifications
You must be signed in to change notification settings - Fork 3
/
spm_sum.m
34 lines (31 loc) · 1015 Bytes
/
spm_sum.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
function S = spm_sum(varargin)
% Sum of elements
% FORMAT S = spm_sum(X,vecdim)
%
% Compatibility layer for SUM for MATLAB < R2018b
%__________________________________________________________________________
% Copyright (C) 2020 Wellcome Centre for Human Neuroimaging
% Guillaume Flandin
% $Id: spm_sum.m 7814 2020-04-06 11:47:47Z guillaume $
# SPDX-License-Identifier: GPL-2.0
persistent usebuiltin
% Turn off use of builtins for Octave compatibility. Add these again later toascii
% Improve performance
if isempty(usebuiltin)
%usebuiltin = strcmp(spm_check_version,'matlab') && ...
%spm_check_version('matlab','9.5') >= 0;
usebuiltin = 0;
end
if usebuiltin
S = sum(varargin{:});
else
if nargin == 2 && isnumeric(varargin{2}) && numel(varargin{2}) > 1
vecdim = varargin{2};
S = sum(varargin{1},vecdim(1),varargin{3:end});
for i=2:numel(vecdim)
S = sum(S,vecdim(i),varargin{3:end});
end
else
S = sum(varargin{:});
end
end