Matrix Calculation Code help

2 ビュー (過去 30 日間)
Fayyaz
Fayyaz 2015 年 3 月 23 日
編集済み: John D'Errico 2015 年 3 月 23 日
Hi.
I have two matrices, both have order 81*2. The first matrix includes columns 1)zone no. (from 1 to 81, i.e "i") and 2) P values for these 81 zones. Similarly, the second matrix includes columns 1) zone no.(from 1 to 81, i.e "j") and 2) A values for these 81 zones.
I need to calculate a 81*81 matrix, which values should be according to the formula; Tij= Pi*Aj/ Sum(A). (i.e sum of A 2nd column as a one value).
Also the values for the T11=T22=.......=T81,81 should be equal to ZERO. (I need values only when i is Not equal to j)
I have also uploaded the files. Any help in this regard would be greatly appreciated. Thanks in advance.

採用された回答

John D'Errico
John D'Errico 2015 年 3 月 23 日
編集済み: John D'Errico 2015 年 3 月 23 日
Easy, peasy. No need even for bsxfun.
Just use an outer product to form P(i)*A(j) as an 81x81 matrix. Then, since the sum of A is a scalar, divide by that sum.
P(:,2)*A(:,2).'/sum(A(:,2))

その他の回答 (1 件)

Guillaume
Guillaume 2015 年 3 月 23 日
If I understood correctly, this is one way to do what you want:
bsxfun(@times, P(:, 2), A(:, 2).') / sum(A(:, 2)) .* ~eye(size(P, 1), size(A, 2))

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by