For example, given the matrix
A = [ 1 2 3 ; 4 5 6; 7 8 9];
how do I multiply the column elements to get the result as result=[1*4*7 2*5*8 3*6*9]
C = A . * B multiplies arrays A and B by multiplying corresponding elements. The sizes of A and B must be the same or be compatible. If the sizes of A and B are compatible, then the two arrays implicitly expand to match each other.
Use the prod
function with an optional argument indicating along which dimension the multiplication is to be carried out. For your case,
A=[ 1 2 3 ; 4 5 6; 7 8 9];
prod(A,1)
ans =
28 80 162
prod(A)
gives you this result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With