Azzera filtri
Azzera filtri

element in matrix multiplication to create a new matrix

3 visualizzazioni (ultimi 30 giorni)
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)

Risposta accettata

Marta Salas
Marta Salas il 14 Mar 2014
Modificato: Marta Salas il 14 Mar 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.

Più risposte (1)

Benjamin Avants
Benjamin Avants il 14 Mar 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|

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by