How to check if each two successive rows are identical?

3 ビュー (過去 30 日間)
Sarah A
Sarah A 2019 年 1 月 5 日
コメント済み: Sarah A 2019 年 1 月 5 日
Hello,
Suppose that we have the matrix A(300*100) where each two "successive" rows should be identical, So I want to get another matrix B(150*1) where the first element is one if row 1 and row 2 are identical. And in the second element is zero if row 3 and row 4 are not identical. Can anybody help me in that?
regards,
  2 件のコメント
madhan ravi
madhan ravi 2019 年 1 月 5 日
need a short example
Sarah A
Sarah A 2019 年 1 月 5 日
Sppose that:
A=[ 1 2 3 ; 1 2 3 ; 4 5 6; 4 5 7]
The matrix B(2*1) should put "1" in the first element because row1 and row2 in A are identical. Also it should put "0" in the second element because row3 and row4 in A are bot identical.
So B:
B=[1;0]

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2019 年 1 月 5 日
編集済み: Stephen23 2019 年 1 月 5 日
Just use basic indexing and logical operations:
>> A = [1,2,3;1,2,3;4,5,6;4,5,7]
A =
1 2 3
1 2 3
4 5 6
4 5 7
>> all(A(1:2:end,:)==A(2:2:end,:),2)
ans =
1
0
  1 件のコメント
Sarah A
Sarah A 2019 年 1 月 5 日
Thats it thank you :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by