adding the rows for unique numbers

1 回表示 (過去 30 日間)
MakM
MakM 2022 年 1 月 5 日
回答済み: Walter Roberson 2022 年 1 月 5 日
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

採用された回答

Walter Roberson
Walter Roberson 2022 年 1 月 5 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by