필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Comparing two matrix elements summing third and storing them separately

조회 수: 1 (최근 30일)
N/A
N/A 2019년 7월 7일
마감: MATLAB Answer Bot 2021년 8월 20일
whenever the elemnts in column 1 and 3 both are repeated elsewhere in matrix then only third column should get added up
e.g
A=
18 18 1
17 20 2
18 18 1
17 25 2
19 17 3
18 18 1
19 17 3
then answer should be
18 18 1
17 20 2
18 18 2
17 25 2
19 17 3
18 18 3
19 17 6
After that i want that the final matriz should be of the form
x = [ 17 20 2
17 25 2
18 18 3
19 17 6]

답변 (2개)

madhan ravi
madhan ravi 2019년 7월 7일
T = array2table(A);
t = groupsummary(T,{'A1','A2'},'sum');
x = t{:,[1,2,end]}
  댓글 수: 1
madhan ravi
madhan ravi 2019년 7월 7일
Or:
[u,~,idx] = unique(A(:,1:2),'rows');
x = [u,accumarray(idx,A(:,3),[],@sum)]

Andrei Bobrov
Andrei Bobrov 2019년 7월 7일
[B,BB] = groupsummary(A(:,3),A(:,1:2),'sum');
out = [BB{:},B];

이 질문은 마감되었습니다.

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by