If same value apperas in array count +1

조회 수: 3 (최근 30일)
First Last
First Last 2021년 9월 14일
댓글: First Last 2021년 9월 14일
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일
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
First Last
First Last 2021년 9월 14일
Thats it, thank you Walter :) you saved my day

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

추가 답변 (1개)

KSSV
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
  댓글 수: 1
First Last
First Last 2021년 9월 14일
Thank you KSSV,
but i the output is a little bit diffrent

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by