Matrix Manipulation

Hello everyone!
I am a layman for Matlab, so please forgive me if the question sounds naive. Here is my question. Let's say I have a 3x3 matrix called X:
X = [1 2 3;4 5 6; 7 8 9]
I would like to generate a new matrix Z from X such that every cell Z(i,j) will be defined as follows:
Z(i,j) = X(i,k)*X(k,j) .
where the total number of X cells which are multiplied depends on the length of the matrix.
For example, the first cell of Z will be Z(1,1) = X(1,2)*X(2,1) * X(1,3)*X(3,1)* X(1,1)*X(1,1).
Can any one tell me how to code this in matlab?
Thanks! A.

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2011 年 11 月 19 日

0 投票

Z = prod(bsxfun(@times,permute(X,[1 3 2]),permute(X,[3 2 1])),3);

この質問は閉じられています。

タグ

タグが未入力です。

質問済み:

2011 年 11 月 19 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by