1 |
adcroft |
1.2 |
function [varargout] = stats(A) |
2 |
|
|
% stats(A) writes the basic statistics of the A to the terminal which |
3 |
|
|
% are i) the minimum finite value |
4 |
|
|
% ii) the maximum finite value |
5 |
|
|
% iii) the mean of the finite values |
6 |
|
|
% iv) the S.D. of the finite values ( RMS of [A-mean] ) |
7 |
|
|
% v) the fraction of non-finite elements excluded from calculations |
8 |
|
|
% |
9 |
|
|
% e.g. |
10 |
|
|
% >> stats(topo) |
11 |
|
|
% Min -4555 Max 0 Mean -2331.07 SD 1207.3441 N-Z 1024/1024 |
12 |
|
|
% |
13 |
|
|
% [Min Max Mean SD]=stats(topo); returns the statistics in Min, Max, |
14 |
|
|
% Mean and SD and does not write to the terminal. |
15 |
|
|
% |
16 |
adcroft |
1.3 |
% $Header: /u/gcmpack/models/MITgcmUV/utils/matlab/stats.m,v 1.2 2001/05/29 14:01:41 adcroft Exp $ |
17 |
|
|
|
18 |
|
|
A=A(:); |
19 |
adcroft |
1.2 |
|
20 |
|
|
%ii=find(A~=0); |
21 |
|
|
ii=find(isfinite(A)); |
22 |
|
|
if isempty(ii) |
23 |
|
|
ii=1; |
24 |
|
|
end |
25 |
|
|
sZ=prod(size(A)); |
26 |
|
|
minA=min(A(ii)); |
27 |
|
|
maxA=max(A(ii)); |
28 |
|
|
meanA=mean(A(ii)); |
29 |
|
|
sdA=sqrt( mean( (A(ii)-meanA).^2 ) ); |
30 |
adcroft |
1.3 |
nZ=sum(~isfinite(A)); |
31 |
adcroft |
1.2 |
switch max(nargout) |
32 |
|
|
case {0} |
33 |
|
|
disp( ... |
34 |
|
|
sprintf('Min %0.5g Max %0.5g Mean %0.5g SD %0.5g NaN %i/%i',... |
35 |
|
|
minA,maxA,meanA,sdA,nZ,sZ) ); |
36 |
|
|
case {1} |
37 |
|
|
varargout(1)={minA}; |
38 |
|
|
case {2} |
39 |
|
|
varargout(1)={minA}; |
40 |
|
|
varargout(2)={maxA}; |
41 |
|
|
case {3} |
42 |
|
|
varargout(1)={minA}; |
43 |
|
|
varargout(2)={maxA}; |
44 |
|
|
varargout(3)={meanA}; |
45 |
|
|
case {4} |
46 |
|
|
varargout(1)={minA}; |
47 |
|
|
varargout(2)={maxA}; |
48 |
|
|
varargout(3)={meanA}; |
49 |
|
|
varargout(4)={sdA}; |
50 |
|
|
otherwise |
51 |
|
|
error('Too many return arguments requested') |
52 |
|
|
end |