Size of the unique elements and size of the output of accumarray

6 次查看(过去 30 天)
Why are the sizes of the two arrays, unique and accumarray, not the same?
size(unique(MAT(:,1)))
size(accumarray(MAT(:,1),MAT(:,2)))

采纳的回答

Matt J
Matt J 2021-8-8
编辑:Matt J 2021-8-8
They will only be the same size if unique(MAT(:,1)) consists of consecutive integers starting from 1. Otherwise, accumarray must leave certain spots blank. A simpler example:
accumarray([2;4],1)
ans = 4×1
0 1 0 1

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by