0001 function s = trunc_singular(s, tol, relative, maxrank)
0002
0003
0004
0005
0006
0007
0008
0009 if ~exist('relative','var'), relative = true; end
0010 if ~exist('maxrank','var'), maxrank = length(s); end
0011
0012 summ = cumsum(s.^2,'reverse');
0013
0014 if relative
0015 s = find(summ > tol^2, 1, 'last');
0016 if isempty(s), s = 1; end
0017 else
0018 s = find(summ > tol^2*summ(1), 1, 'last');
0019 if isempty(s), s = 1; end
0020 end
0021
0022 s = min([s, maxrank, length(s)]);
0023
0024 end
0025