开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜