フィルターのクリア

How to detect repeated values between rows?

2 ビュー (過去 30 日間)
Grace
Grace 2014 年 8 月 16 日
回答済み: Michael Haderlein 2014 年 8 月 16 日
Hi I have
a= 1 2
3 1
2 3
2 3
3 2
1 1
I want to detect whether this matrix has repeated elements between rows or not. The condition is, the row must be subsequent to each other. Obviously, 3rd and 4th rows have same elements, hence display 'hello'. For another example,
b= 1 2
2 3
3 1
2 3
3 2
1 1
'b' have repeated elements in 2nd and 4th rows, but it does not fulfill the condition that the row is subsequent to another row. Hence, 'hello' will not be displayed.
How am I going to do this? Thank you.

採用された回答

Michael Haderlein
Michael Haderlein 2014 年 8 月 16 日
You can use the diff function:
if any(sum(abs(diff(a,1)),2)==0)
msgbox('hello')
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by