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

 채택된 답변

Walter Roberson
Walter Roberson 2011년 11월 28일

0 개 추천

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

댓글 수: 2

Andrei Bobrov
Andrei Bobrov 2011년 11월 29일
Hi Walter! Small typo, should be:
all(diff(a,1,2)==0,2)
Walter Roberson
Walter Roberson 2011년 11월 29일
Thanks for catching that -- I didn't know that. I have edited to fix.

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

추가 답변 (1개)

michelef
michelef 2011년 11월 29일

0 개 추천

many thanks :) have a nice day :)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by