필터 지우기
필터 지우기

comparing two matrix element simultaneously and adding third column

조회 수: 1 (최근 30일)
N/A
N/A 2019년 7월 5일
댓글: N/A 2019년 7월 7일
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

채택된 답변

KSSV
KSSV 2019년 7월 5일
A = [ 18 18 1
17 20 2
18 18 1
17 25 2
19 17 3
18 18 1
19 17 3] ;
[c,ia,ib] = unique(A(:,1:2),'rows') ;
B = A ;
% [c,ia,ib] = unique(A(:,3)) ;
for i = 1:length(c)
B(ib==i,3) = cumsum(A(ib==i,3)) ;
end
B
  댓글 수: 1
N/A
N/A 2019년 7월 7일
thank you KSSV this works absolutely fine but since my actual matrix is going to be 3x11870 i want that the unique elements and their cumulative sum should be stored separately otherwise it would be too difficult to find them can you tell me how that will work thanks in advance.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by