Borrar filtros
Borrar filtros

Vector counting syntax help?

2 visualizaciones (últimos 30 días)
James Baker
James Baker el 9 de Mayo de 2021
Comentada: Star Strider el 9 de Mayo de 2021
if i have a vector A = [1 1 1 1 2 3 3 5 5 5 5 6 6 7]... its alreay been sortecand only increases.. i want to create a 2nd vector based off A say called B that would have the count of each unique values in the A vector... so, B = [3 1 2 3 2 1] .. because there are 3 1's and 1 2 and 2 3's, etc etc. i just cant seem to get the suntax correct... please help.

Respuesta aceptada

Star Strider
Star Strider el 9 de Mayo de 2021
Try this —
A = [1 1 1 1 2 3 3 5 5 5 5 6 6 7];
[Au,~,ix] = unique(A,'stable');
Count = accumarray(ix,1);
Result = table(Au(:), Count(:), 'VariableNames',{'Unique_Elements','Count'})
Result = 6×2 table
Unique_Elements Count _______________ _____ 1 4 2 1 3 2 5 4 6 2 7 1
.
  4 comentarios
James Baker
James Baker el 9 de Mayo de 2021
ok.. perfect.. after looking at it for a few... just what i needed thanks
Star Strider
Star Strider el 9 de Mayo de 2021
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by