开发者

How do I multiply the elements in each column, for every column in a matrix in MATLAB?

开发者 https://www.devze.com 2023-03-03 15:32 出处:网络
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 optiona

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消