forked from Shrediquette/PIVlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnanmax.m
67 lines (63 loc) · 1.82 KB
/
nanmax.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function [y,idx] = nanmax(a,dim,b)
% FORMAT: [Y,IDX] = NANMAX(A,DIM,[B])
%
% Maximum ignoring NaNs
%
% This function enhances the functionality of NANMAX as distributed in
% the MATLAB Statistics Toolbox and is meant as a replacement (hence the
% identical name).
%
% If fact NANMAX simply rearranges the input arguments to MAX because
% MAX already ignores NaNs.
%
% NANMAX(A,DIM) calculates the maximum of A along the dimension DIM of
% the N-D array X. If DIM is omitted NANMAX calculates the maximum along
% the first non-singleton dimension of X.
%
% NANMAX(A,[],B) returns the minimum of the N-D arrays A and B. A and
% B must be of the same size.
%
% Comparing two matrices in a particular dimension is not supported,
% e.g. NANMAX(A,2,B) is invalid.
%
% [Y,IDX] = NANMAX(X,DIM) returns the index to the maximum in IDX.
%
% Similar replacements exist for NANMIN, NANMEAN, NANSTD, NANMEDIAN and
% NANSUM which are all part of the NaN-suite.
%
% See also MAX
% -------------------------------------------------------------------------
% author: Jan Gläscher
% affiliation: Neuroimage Nord, University of Hamburg, Germany
% email: glaescher@uke.uni-hamburg.de
%
% $Revision: 1.1 $ $Date: 2004/07/15 22:42:11 $
if nargin < 1
error('Requires at least one input argument')
end
if nargin == 1
if nargout > 1
[y,idx] = max(a);
else
y = max(a);
end
elseif nargin == 2
if nargout > 1
[y,idx] = max(a,[],dim);
else
y = max(a,[],dim);
end
elseif nargin == 3
if ~isempty(dim)
error('Comparing two matrices along a particular dimension is not supported')
else
if nargout > 1
[y,idx] = max(a,b);
else
y = max(a,b);
end
end
elseif nargin > 3
error('Too many input arguments.')
end
% $Id: nanmax.m,v 1.1 2004/07/15 22:42:11 glaescher Exp glaescher $