element in matrix multiplication to create a new matrix
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
lo
el 14 de Mzo. de 2014
Editada: Marta Salas
el 14 de Mzo. de 2014
A and O is 3x1 matrix
B and D is 1x3 matrix
f is a 3x3 matrix
What is wrong with the code below?
i=1:3
j=1:3
T(i,j)=A(i).*B(j).*O(i).*D(j).*f(i,j)
0 comentarios
Respuesta aceptada
Marta Salas
el 14 de Mzo. de 2014
Editada: Marta Salas
el 14 de Mzo. de 2014
Your code doesn't run because you are using .* which is element wise multiplication instead of standar matrix multiplication. You can do:
for i=1:3
for j=1:3
T(i,j)=A(i).*B(j).*O(i).*D(j).*f(i,j)
end
end
or
T=A*B*O*D*f
depending on the result you are expecting.
0 comentarios
Más respuestas (1)
Benjamin Avants
el 14 de Mzo. de 2014
Your question is a little unclear, but if you want to do matrix multiplication like this:
|d|
|a,b,c| * |e| = (ad+be+fc)
|f|
or this
|a| |ae,af,ag|
|b| * |e,f,g| = |be,bf,bg|
|c| |ce,cf,cg|
then you want to use the normal * operator and not the .* operator.
The .* operator will multiply a constant by each element in the matrix or array. It will also do elementwise multiplication on arrays of the same size.
Example:
|a,b| |e,f| |ae,bf|
|c,d| .* |g,h| = |ag,dh|
0 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices 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!