How to multiply each elements of single matrix one-by-one?
28 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Beibit Sautbek
le 18 Juil 2016
Modifié(e) : Stephen23
le 18 Juil 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?
0 commentaires
Réponse acceptée
James Tursa
le 18 Juil 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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!