How to make comparison between paired elements?

3 Ansichten (letzte 30 Tage)
Patty
Patty am 19 Jun. 2014
Kommentiert: Star Strider am 19 Jun. 2014
Hi, I would like to compare pair of adjacent elements of array. For example:
if
A=[1;
2;
1;
3;
2;
4]
In this case the pairs are (1 2) (1 3) (2 4)... So in this case I have "unique" pairs.
But for example:
A=[1;
2;
1;
2;
2;
4]
In this case the pairs are (1 2) (1 2) (2 4) .... In this case I don't have "unique" pairs.
How can I make the comparisson of pairs, considering the pair is form with the adjacent element.
thanks

Akzeptierte Antwort

Star Strider
Star Strider am 19 Jun. 2014
A=[1;
2;
1;
2;
2;
4]
Ar = reshape(A, 2, [])';
UA = unique(Ar,'rows')
The ‘UA’ matrix rows are the unique adjacent elements of your ‘A’ vector.
  4 Kommentare
Patty
Patty am 19 Jun. 2014
I got it using your suggestions... Thanks so much!.. Just a little change.
D=reshape(A,2,[]);
F=sum(D);
anyRepeated = length(unique(F) < length(F));
if anyRepeated<length(F)
passFlag2=0;
else
passFlag2=1;
end
I just copied here, in case somebody else needed.. :)
Star Strider
Star Strider am 19 Jun. 2014
My pleasure!
And thank you arich82.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays 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