matlab中两个矩阵的一些计算

时间:2012-06-26 00:49:01

标签: matlab

我有两个矩阵:矩阵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)

2 个答案:

答案 0 :(得分:1)

如果我理解正确,您希望将1添加到数组a,并分别除以行和列总和的乘积。

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

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

out = (a+1)./denominator;

答案 1 :(得分:0)

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

rel = sum(a);
TS = (a + 1) ./ (rel' * rel);