Unknow fail using accumarray

Hello good day I am new to this forum so I introduce myself, I am a student who is trying to finish a job, the problem is that I have programmed with MATLAB2014 and very little of it. My problem is that I have two vectors that give the position of different points and I need a similar function to accumArray to represent a bivariate histogram but accumArray gives me fail cause of vectors have negative numbers. Any help, thanks in advance. A greeting.

回答 (2 件)

Stephen23
Stephen23 2016 年 3 月 24 日
編集済み: Stephen23 2016 年 3 月 24 日

0 投票

You can use unique to get the required indices:
>> A = [0,-1,1,-2,-1,1]; % values to group by (including negative)
>> B = [1,23,4,56,78,9]; % corresponding values to sum together
>> [vec,~,idx] = unique(A);
>> accumarray(idx(:),B,[],@sum)
ans =
56
101
1
13
>> vec(:) % each group's "value"
ans =
-2
-1
0
1
Steven Lord
Steven Lord 2016 年 3 月 24 日

0 投票

You may want to upgrade to release R2015b or later and use the histogram2 function.

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

タグ

質問済み:

2016 年 3 月 24 日

回答済み:

2016 年 3 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by