compare elements in rows of a matrix

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

 Accepted Answer

One way:
all(diff(a,1,2)==0,2)

2 Comments

Hi Walter! Small typo, should be:
all(diff(a,1,2)==0,2)
Thanks for catching that -- I didn't know that. I have edited to fix.

Sign in to comment.

More Answers (1)

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

Categories

Community Treasure Hunt

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

Start Hunting!