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.

Answers (1)

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

This question is closed.

Tags

No tags entered yet.

Asked:

on 19 Nov 2011

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!