adding the rows for unique numbers

2 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 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

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!