If same value apperas in array count +1

1 Ansicht (letzte 30 Tage)
First Last
First Last am 14 Sep. 2021
Kommentiert: First Last am 14 Sep. 2021
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 14 Sep. 2021
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 Kommentar
First Last
First Last am 14 Sep. 2021
Thats it, thank you Walter :) you saved my day

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

KSSV
KSSV am 14 Sep. 2021
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 Kommentar
First Last
First Last am 14 Sep. 2021
Thank you KSSV,
but i the output is a little bit diffrent

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by