How to multiply each elements of single matrix one-by-one?

조회 수: 27 (최근 30일)
Beibit Sautbek
Beibit Sautbek 2016년 7월 18일
편집: Stephen23 2016년 7월 18일
I have a matrix Xij:
Xij =[
0 1 -2 2 6
-1 0 -3 1 5
2 3 0 4 8
-2 -1 -4 0 4
-6 -5 -8 -4 0];
I need to multiply each elements of this matrix with each elements of this matrix again. For example, I need to multiply X13*X24 or X12*X24. And I need to multiply for all matrix.
I have tried the code below, but it multiplies just X11*X11 (like square):
Xij =[
0 1 -2 2 6
-1 0 -3 1 5
2 3 0 4 8
-2 -1 -4 0 4
-6 -5 -8 -4 0];
for m=1:5
for n=1:5
A(m,n)=Xij(m,n)*Xij(m,n);
end
end
I got unnecessary result like:
A =
0 1 4 4 36
1 0 9 1 25
4 9 0 16 64
4 1 16 0 16
36 25 64 16 0
Could anyone help me, please?

채택된 답변

James Tursa
James Tursa 2016년 7월 18일
This will multiply every element by every other element:
result = Xij(:) * Xij(:)'; % <-- Simple outer product of all the elements
If you want the resulting elements to be in a specific order, or the size of the result to be in a specific shape, please specify.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by