フィルターのクリア

Is there a multiplicative accumarray function?

2 ビュー (過去 30 日間)
Christopher
Christopher 2014 年 3 月 14 日
編集済み: the cyclist 2014 年 3 月 14 日
I am using accumarray to additively accumulate numbers with a code like the following:
wts = accumarray([P(:,2),P(:,1)],P(:,3),size(net));
Is there a function, or a simple vectorized method, to do the exact same thing with one difference: instead of adding the numbers, multiply them?
If accumarray finds numbers N1, N2, N3... it will add them as N1+N2+N3...
However, I want a function to multiply them as N1*N2*N3...
Thanks

回答 (1 件)

the cyclist
the cyclist 2014 年 3 月 14 日
編集済み: the cyclist 2014 年 3 月 14 日
accumarray() takes an optional fourth argument, which is the function to apply. You should be able to add @prod to do what you want.
Here is the example from the documentation:
val = 101:105;
subs = [1 1; 2 1; 2 3; 2 1; 2 3];
A = accumarray(subs, val, [2 4], @prod, 0, true)
Read
doc accumarray
for details.

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by