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

1 Ansicht (letzte 30 Tage)
Why are the sizes of the two arrays, unique and accumarray, not the same?
size(unique(MAT(:,1)))
size(accumarray(MAT(:,1),MAT(:,2)))

Akzeptierte Antwort

Matt J
Matt J am 8 Aug. 2021
Bearbeitet: Matt J am 8 Aug. 2021
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

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by