| 1 |
function corM = fn_corr(covM) |
| 2 |
% function corM = fn_corr(covM) |
| 3 |
% |
| 4 |
% covM: covariance matrix (input) |
| 5 |
% corM: correlation matrix (output) |
| 6 |
% 6 September 1998 |
| 7 |
% |
| 8 |
% Copyright (C) 1997-2012 Tao Zha |
| 9 |
% |
| 10 |
% This free software: you can redistribute it and/or modify |
| 11 |
% it under the terms of the GNU General Public License as published by |
| 12 |
% the Free Software Foundation, either version 3 of the License, or |
| 13 |
% (at your option) any later version. |
| 14 |
% |
| 15 |
% It is distributed in the hope that it will be useful, |
| 16 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
% GNU General Public License for more details. |
| 19 |
% |
| 20 |
% If you did not received a copy of the GNU General Public License |
| 21 |
% with this software, see <http://www.gnu.org/licenses/>. |
| 22 |
% |
| 23 |
|
| 24 |
|
| 25 |
[nvar,jnk]=size(covM); |
| 26 |
if nvar~=jnk |
| 27 |
error('The input matrix must be square!!') |
| 28 |
end |
| 29 |
corM=zeros(nvar); |
| 30 |
for i=1:nvar |
| 31 |
for j=1:nvar |
| 32 |
corM(i,j)=covM(i,j) / sqrt( covM(i,i) * covM(j,j)); |
| 33 |
end |
| 34 |
end |
| 35 |
|