adding the rows for unique numbers
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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)
0 Comments
More Answers (0)
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!