element in matrix multiplication to create a new matrix

조회 수: 5 (최근 30일)
lo
lo 2014년 3월 14일
편집: Marta Salas 2014년 3월 14일
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)

채택된 답변

Marta Salas
Marta Salas 2014년 3월 14일
편집: Marta Salas 2014년 3월 14일
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.

추가 답변 (1개)

Benjamin Avants
Benjamin Avants 2014년 3월 14일
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|

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by