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