Back to home page

MITgcm

 
 

    


Warning, /utils/matlab/stats.m is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
aea29c8517 Alis*0001 function [varargout] = stats(A)
                0002 % stats(A) writes the basic statistics of the A to the terminal which
                0003 % are i) the minimum finite value
                0004 %    ii) the maximum finite value
                0005 %   iii) the mean of the finite values
                0006 %    iv) the S.D. of the finite values ( RMS of [A-mean] )
                0007 %     v) the fraction of non-finite elements excluded from calculations
                0008 %
                0009 % e.g.
                0010 %  >> stats(topo)
                0011 % Min -4555     Max 0         Mean -2331.07  SD 1207.3441   N-Z 1024/1024
                0012 %
                0013 % [Min Max Mean SD]=stats(topo); returns the statistics in Min, Max,
                0014 % Mean and SD and does not write to the terminal.
7f0effbc3a Jean*0015 
73a5ad7d56 Alis*0016 A=A(:);
aea29c8517 Alis*0017 
                0018 %ii=find(A~=0);
                0019 ii=find(isfinite(A));
                0020 if isempty(ii)
                0021  ii=1;
                0022 end
                0023 sZ=prod(size(A));
                0024 minA=min(A(ii));
                0025 maxA=max(A(ii));
                0026 meanA=mean(A(ii));
                0027 sdA=sqrt( mean( (A(ii)-meanA).^2 ) );
22586ff4d2 Alis*0028 rmsA=sqrt( mean( A(ii).^2 ) );
73a5ad7d56 Alis*0029 nZ=sum(~isfinite(A));
aea29c8517 Alis*0030 switch max(nargout)
                0031  case {0}
22586ff4d2 Alis*0032 % disp( ...
                0033 %  sprintf('Min %0.5g  Max %0.5g  Mean %0.5g  SD %0.5g   NaN %i/%i',...
                0034 %        minA,maxA,meanA,sdA,nZ,sZ) );
aea29c8517 Alis*0035   disp( ...
22586ff4d2 Alis*0036    sprintf('Min %0.5g  Max %0.5g  Mean %0.5g  RMS %0.5g   NaN %i/%i',...
                0037          minA,maxA,meanA,rmsA,nZ,sZ) );
aea29c8517 Alis*0038  case {1}
                0039   varargout(1)={minA};
                0040  case {2}
                0041   varargout(1)={minA};
                0042   varargout(2)={maxA};
                0043  case {3}
                0044   varargout(1)={minA};
                0045   varargout(2)={maxA};
                0046   varargout(3)={meanA};
                0047  case {4}
                0048   varargout(1)={minA};
                0049   varargout(2)={maxA};
                0050   varargout(3)={meanA};
                0051   varargout(4)={sdA};
                0052  otherwise
                0053   error('Too many return arguments requested')
                0054 end