Filter löschen
Filter löschen

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

4 Ansichten (letzte 30 Tage)
Beibit Sautbek
Beibit Sautbek am 18 Jul. 2016
Bearbeitet: Stephen23 am 18 Jul. 2016
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?

Akzeptierte Antwort

James Tursa
James Tursa am 18 Jul. 2016
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.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by