find where number changes in a matrix

I have a matrix of +1 and -1 values. I want to find where the number flips from 1 to -1 or vice versa where the change is a change from column to column.
X=[...
1 1 1 1;
1 -1 1 1;
1 1 1 -1;
1 1 1 1]
the answer should be [2,2],[2,3]and [3,4]. I tried
find(diff(X)==2);
find(diff(X)==-2);
Any help is appreciated

 채택된 답변

Cedric
Cedric 2013년 3월 23일

0 개 추천

>> [r,c] = find(diff(X,1,2)) ;
>> loc = [r, c+1]
loc =
2 2
2 3
3 4

추가 답변 (1개)

the cyclist
the cyclist 2013년 3월 23일

0 개 추천

One way:
[i j] = find(abs([zeros(4,1),diff(X,[],2)])==2)

카테고리

도움말 센터File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

질문:

2013년 3월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by