Effacer les filtres
Effacer les filtres

adding the rows for unique numbers

2 vues (au cours des 30 derniers jours)
MakM
MakM le 5 Jan 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

Réponse acceptée

Walter Roberson
Walter Roberson le 5 Jan 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

Plus de réponses (0)

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by