matlab计算同行不同列的两个矩阵的相关系数。

求教!!
数据源:nowsl矩阵(4*18),tzsl矩阵(4*46)
计算目的:计算nowsl矩阵中每一列向量与tzsl中每一列向量的相关系数,并将相关系数(不是矩阵)返回到dist矩阵中。
问题:
for j=1:18
for i=1:46
dist(i,j)=xcorr(nowsl(:,j),tzsl(:,i));
end
end
根据以上程序,总是出现下表赋值不匹配现象,不知道怎么做?而自相关函数corrcoef返回的是一个矩阵,而不是一个数字。问下该怎么做?

 Réponse acceptée

viyemej
viyemej le 23 Nov 2022

0 votes

没有必要用二重循环,corr 函数可以直接对两个矩阵的列两两求互相关,得到的正好是你需要的互相关系数矩阵。所以,你的二重循环代码:
for j=1:18
for i=1:46
dist(i,j)=corr(nowsl(:,j),tzsl(:,i));
end
end
可以简化为1句代码:
dist = corr(tzsl,nowsl);

Plus de réponses (0)

Catégories

En savoir plus sur 描述性统计量 dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!