## [Octave-cvsupdate] octave-forge/extra/NaN cov.m,1.7,1.8

 [Octave-cvsupdate] octave-forge/extra/NaN cov.m,1.7,1.8 From: Alois Schloegl - 2005-03-02 17:57:32 ```Update of /cvsroot/octave/octave-forge/extra/NaN In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10834 Modified Files: cov.m Log Message: address incompatibility with COV in MATLAB Index: cov.m =================================================================== RCS file: /cvsroot/octave/octave-forge/extra/NaN/cov.m,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- cov.m 2 Mar 2003 19:59:21 -0000 1.7 +++ cov.m 2 Mar 2005 17:57:20 -0000 1.8 @@ -11,22 +11,25 @@ % calculates the crosscorrelation between X and Y. % C(i,j) is the correlation between the i-th and jth % column of X and Y, respectively. -% NOTE: this is different than the behaviour of DATAFUN\COV. -% Use COV([X(:),Y(:)]) to get the traditional behaviour of Matlab. +% NOTE: Octave and Matlab have (in some special cases) incompatible implemenations. +% This implementation follows Octave. If the result could be ambigous or +% incompatible, a warning will be presented in Matlab. To avoid this warning use: +% a) use COV([X(:),Y(:)]) if you want the traditional Matlab result. +% b) use C = COV([X,Y]), C = C(1:size(X,2),size(X,2)+1:size(C,2)); if you want to be compatible with Octave. % % Mode = 0 [default] scales C by (N-1) % Mode = 1 scales C by N. % -% see also: COVM, SUMSKIPNAN +% see also: COVM, COR, CORRCOEF, SUMSKIPNAN % % REFERENCES: % http://mathworld.wolfram.com/Covariance.html - % \$Revision\$ % \$Id\$ -% Copyright (C) 2000-2003 by Alois Schloegl - +% Copyright (C) 2000-2003,2005 by Alois Schloegl +% This function is part of the NaN-toolbox +% http://www.dpmi.tu-graz.ac.at/~schloegl/matlab/NaN/ % This program is free software; you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -57,20 +60,30 @@ Y = []; else Mode = 0; - if ~exist('OCTAVE_VERSION'), % if Matlab, - fprintf(2,'Warning NaN/COV: Behaviour of COV(X,Y) is unlike in datafun/COV. \nSee HELP COV for more information.\n'); - end; end; elseif nargin==3, else fprintf(2,'Error COV: invalid number of arguments\n'); end; - + +if ~exist('OCTAVE_VERSION','builtin') & ~isempty(Y) & (size(X,2)+size(Y,2)~=2), + % COV in Matlab is differently defined than COV in Octave. + % For compatibility reasons, this branch reflects the difference. + fprintf(2,'Warning NaN/COV: This kind of use of COV is discouraged because it produces different results for Matlab and Octave. \n'); + fprintf(2,' (a) the traditional Matlab result can be obtained with: C = COV([X(:),Y(:)]).\n'); + fprintf(2,' (b) the traditional Octave result can be obtained with: C = COV([X,Y]); C = C(1:size(X,2),size(X,2)+1:size(C,2)).\n'); + + if prod(size(Y))~=prod(size(X)), + error('The lengths of X and Y must match.'); + end; + X = [X(:),Y(:)]; + Y = []; +end; if isempty(Y) - CC = covm(X,['D',int2str(Mode)]); + CC = covm(X,['D',int2str(Mode>0)]); else - CC = covm(X,Y,['D',int2str(Mode)]); + CC = covm(X,Y,['D',int2str(Mode>0)]); end; ```

 [Octave-cvsupdate] octave-forge/extra/NaN cov.m,1.7,1.8 From: Alois Schloegl - 2005-03-02 17:57:32 ```Update of /cvsroot/octave/octave-forge/extra/NaN In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10834 Modified Files: cov.m Log Message: address incompatibility with COV in MATLAB Index: cov.m =================================================================== RCS file: /cvsroot/octave/octave-forge/extra/NaN/cov.m,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- cov.m 2 Mar 2003 19:59:21 -0000 1.7 +++ cov.m 2 Mar 2005 17:57:20 -0000 1.8 @@ -11,22 +11,25 @@ % calculates the crosscorrelation between X and Y. % C(i,j) is the correlation between the i-th and jth % column of X and Y, respectively. -% NOTE: this is different than the behaviour of DATAFUN\COV. -% Use COV([X(:),Y(:)]) to get the traditional behaviour of Matlab. +% NOTE: Octave and Matlab have (in some special cases) incompatible implemenations. +% This implementation follows Octave. If the result could be ambigous or +% incompatible, a warning will be presented in Matlab. To avoid this warning use: +% a) use COV([X(:),Y(:)]) if you want the traditional Matlab result. +% b) use C = COV([X,Y]), C = C(1:size(X,2),size(X,2)+1:size(C,2)); if you want to be compatible with Octave. % % Mode = 0 [default] scales C by (N-1) % Mode = 1 scales C by N. % -% see also: COVM, SUMSKIPNAN +% see also: COVM, COR, CORRCOEF, SUMSKIPNAN % % REFERENCES: % http://mathworld.wolfram.com/Covariance.html - % \$Revision\$ % \$Id\$ -% Copyright (C) 2000-2003 by Alois Schloegl - +% Copyright (C) 2000-2003,2005 by Alois Schloegl +% This function is part of the NaN-toolbox +% http://www.dpmi.tu-graz.ac.at/~schloegl/matlab/NaN/ % This program is free software; you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by @@ -57,20 +60,30 @@ Y = []; else Mode = 0; - if ~exist('OCTAVE_VERSION'), % if Matlab, - fprintf(2,'Warning NaN/COV: Behaviour of COV(X,Y) is unlike in datafun/COV. \nSee HELP COV for more information.\n'); - end; end; elseif nargin==3, else fprintf(2,'Error COV: invalid number of arguments\n'); end; - + +if ~exist('OCTAVE_VERSION','builtin') & ~isempty(Y) & (size(X,2)+size(Y,2)~=2), + % COV in Matlab is differently defined than COV in Octave. + % For compatibility reasons, this branch reflects the difference. + fprintf(2,'Warning NaN/COV: This kind of use of COV is discouraged because it produces different results for Matlab and Octave. \n'); + fprintf(2,' (a) the traditional Matlab result can be obtained with: C = COV([X(:),Y(:)]).\n'); + fprintf(2,' (b) the traditional Octave result can be obtained with: C = COV([X,Y]); C = C(1:size(X,2),size(X,2)+1:size(C,2)).\n'); + + if prod(size(Y))~=prod(size(X)), + error('The lengths of X and Y must match.'); + end; + X = [X(:),Y(:)]; + Y = []; +end; if isempty(Y) - CC = covm(X,['D',int2str(Mode)]); + CC = covm(X,['D',int2str(Mode>0)]); else - CC = covm(X,Y,['D',int2str(Mode)]); + CC = covm(X,Y,['D',int2str(Mode>0)]); end; ```