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

 채택된 답변

Walter Roberson
Walter Roberson 2021년 9월 14일

1 개 추천

input = [ 1 2 3 4 1 2 3 4 1 2 3 4 ];
output = sum(triu(input' == input))
output = 1×12
1 1 1 1 2 2 2 2 3 3 3 3

추가 답변 (1개)

KSSV
KSSV 2021년 9월 14일

1 개 추천

input = [ 1 2 3 4 1 2 3 4 1 2 3 4 ];
a = reshape(input,[],3)' ;
[c,ia,ib] = unique(a,'rows') ;
ib

댓글 수: 1

First Last
First Last 2021년 9월 14일
Thank you KSSV,
but i the output is a little bit diffrent

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

카테고리

도움말 센터File Exchange에서 Calendar에 대해 자세히 알아보기

질문:

2021년 9월 14일

댓글:

2021년 9월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by