Hi
I have the following scenario, consider the matrix a a =
1 2 10
1 2 20
2 1 11
2 2 10
2 1 1
I want to merge rows for the matrix a based on the first two columns where the first two columns have same values. My resultant should look like
res =
1 2 30
2 1 12
2 2 10
How to do so with minimal or no loops.
Thanks

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 5 月 10 日
編集済み: Azzi Abdelmalek 2013 年 5 月 10 日

2 投票

a=[ 1 2 10
1 2 20
2 1 11
2 2 10
2 1 1]
[ii,jj,kk]=unique(a(:,1:2),'rows','stable')
out=[ii accumarray(kk,a(:,3))]

1 件のコメント

Nitin
Nitin 2013 年 5 月 10 日
Thanks a bunch this works perfect!!!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by