0

我有两个矩阵:矩阵a(6*6 主矩阵)和矩阵b(14*2 包含矩阵 a 中元素之间的关系):

a = [
 0 1 0 0 1 1
 1 0 1 1 0 0
 0 1 0 1 0 0
 0 1 1 0 0 1
 1 0 0 0 0 0
 1 0 0 1 0 0 ]

b= [
 1 2
 1 5
 1 6
 2 1
 2 3
 2 4
 3 2
 3 4
 4 2
 4 3
 4 6
 5 1
 6 1
 6 4 ]

我需要计算以下内容:

TS(i,j)=(a(i,j)+1)/(the number of elements related to i(from matrix b)
    * the number of elements related to j(from matrix b))

例如:TS(1,2)=((1)+1)/(3*3)

4

2 回答 2

1

如果我理解正确,您想将 1 添加到 array a,然后分别除以行和列总和的乘积。

colSum = sum(a,1);
rowSum = sum(a,2);

denominator = bsxfun(@times,colSum,rowSum);

out = (a+1)./denominator;
于 2012-06-26T02:15:22.800 回答
0

如果我正确理解您的问题,这应该可以满足您的需求:

rel = sum(a);
TS = (a + 1) ./ (rel' * rel);
于 2012-06-26T01:27:49.203 回答