corr2.m

来自「有关matlab的电子书籍有一定的帮助希望有用」· M 代码 · 共 28 行

M
28
字号
function r = corr2(a,b)
%CORR2 Compute 2-D correlation coefficient.
%   R = CORR2(A,B) computes the correlation coefficient between A
%   and B, where A and B are matrices or vectors of the same size.
%
%   See also CORRCOEF, STD2.

%   Clay M. Thompson 10-6-92
%   Copyright 1993-1998 The MathWorks, Inc.  All Rights Reserved.
%   $Revision: 5.7 $  $Date: 1997/11/24 15:34:25 $

error(nargchk(2,2,nargin));

if any(size(a)~=size(b)), error('A and B must be the same size.'); end

if (~isa(a,'double'))
    a = double(a);
end

if (~isa(b,'double'))
    b = double(b);
end

a = a - mean2(a);
b = b - mean2(b);

r = sum(sum(a.*b))/sqrt(sum(sum(a.*a))*sum(sum(b.*b)));

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?