Merging cells,adding contents
조회 수: 8 (최근 30일)
이전 댓글 표시
Hey everyone.! I have some data in this form
'Mary' [ 37]
'Lisa' [ 18]
'George' [ 20]
'Nick' [ 49]
'Mary' [ 24]
'George' [ 4]
'Lisa' [ 36]
(random names with random sequence)and I want to have this
'Mary' [ 61]
'Lisa' [ 54]
'George' [ 24]
'Nick' [ 49]
(not necessarily in this order) Any good ideas? Thank you all..
댓글 수: 0
채택된 답변
Azzi Abdelmalek
2013년 11월 17일
v={'Mary' [ 37]
'Lisa' [ 18]
'George' [ 20]
'Nick' [ 49]
'Mary' [ 24]
'George' [ 4]
'Lisa' [ 36]}
[a,b,c]=unique(v(:,1),'stable')
n=accumarray(c,[v{:,2}]')
out=[a num2cell(n)]
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!