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]
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.
精彩评论