How to multiply each elements of single matrix one-by-one?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Beibit Sautbek
el 18 de Jul. de 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 comentarios
Respuesta aceptada
James Tursa
el 18 de Jul. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!