How to element by element multiply all rows of a matrix in a loop?

4 ビュー (過去 30 日間)
Ian
Ian 2014 年 9 月 12 日
コメント済み: Star Strider 2014 年 9 月 12 日
I've written a function which generates an (a x b) matrix where a,b are both inputted quantities. After I've generated this matrix I'd like to multiply all of the rows in the matrix element by element. So I'd be going from an (a x b) matrix to a (1 x b) array. For example: If the (a x b) matrix was [1 2 3; 4 5 6; 7 8 9; 10 11 12] a = 4, b = 3. The (1 x b) array I'd like to end up with would be [1*4*7*10 2*5*8*11 3*6*9*12] = [280 880 1944]. Any ideas on a quick and easy way to generate this (1 x b) array?
Thanks!

採用された回答

Star Strider
Star Strider 2014 年 9 月 12 日
This works:
M = [1 2 3; 4 5 6; 7 8 9; 10 11 12];
r = prod(M)
  2 件のコメント
Ian
Ian 2014 年 9 月 12 日
Perfect! Thanks!
Star Strider
Star Strider 2014 年 9 月 12 日
My pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by