compare elements in rows of a matrix

4 Ansichten (letzte 30 Tage)
michelef
michelef am 28 Nov. 2011
Hi,
I have the following matrix:
a=[1 2 3 9; 2 2 3 1; 3 3 3 3]
is there a function that compares the elements of every row?
Something that tells me if they are all different or all the same.
I would like to get
out=[1 0 0]
or
out=[0 0 1]
thanks,
michele

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 28 Nov. 2011
One way:
all(diff(a,1,2)==0,2)
  2 Kommentare
Andrei Bobrov
Andrei Bobrov am 29 Nov. 2011
Hi Walter! Small typo, should be:
all(diff(a,1,2)==0,2)
Walter Roberson
Walter Roberson am 29 Nov. 2011
Thanks for catching that -- I didn't know that. I have edited to fix.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

michelef
michelef am 29 Nov. 2011
many thanks :) have a nice day :)

Kategorien

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