If same value apperas in array count +1
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello Guys,
I have an array with nx1, now i need a code to count + 1 if the same value apperas later in the array, for example:
input = [ 1 2 3 4 1 2 3 4 1 2 3 4 ];
output = [ 1 1 1 1 2 2 2 2 3 3 3 3];
Thank you
댓글 수: 0
채택된 답변
Walter Roberson
2021년 9월 14일
input = [ 1 2 3 4 1 2 3 4 1 2 3 4 ];
output = sum(triu(input' == input))
추가 답변 (1개)
KSSV
2021년 9월 14일
input = [ 1 2 3 4 1 2 3 4 1 2 3 4 ];
a = reshape(input,[],3)' ;
[c,ia,ib] = unique(a,'rows') ;
ib
참고 항목
카테고리
Help Center 및 File Exchange에서 Calendar에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!