Borrar filtros
Borrar filtros

adding the rows for unique numbers

2 visualizaciones (últimos 30 días)
MakM
MakM el 5 de En. de 2022
Respondida: Walter Roberson el 5 de En. de 2022
I want to add the first column for each unique value in column 3. In this example i want the count 4 for 1 and count equal to 1 for the value 2 in column 3.
A=[0,1,0,1,1,0,0,0,0,1,1,0,0,0] % First column
B=[1,1,1,1,1,1,1,1,1,1,2,2,2,2] %second Column
ans= [4,1] % desired output

Respuesta aceptada

Walter Roberson
Walter Roberson el 5 de En. de 2022
A = [0,1,0,1,1,0,0,0,0,1,1,0,0,0]; % First column
B = [1,1,1,1,1,1,1,1,1,1,2,2,2,2]; %second Column
[G, value] = findgroups(B(:));
total = accumarray(G, A(:));
table(value, total)
ans = 2×2 table
value total _____ _____ 1 4 2 1

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by