Can I replace the row of the matrix when its value is equal to the previous row?
2 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I have a following matrix as a sample/
A = [1 2 3; 4 5 6; 1 2 3; 1 2 3];
And I would like to replace the value of entire row if the row is equal to the previous row.
So in this case,
B = [1 2 3; 4 5 6; 1 2 3; 0 0 0]
Because the last row is equal to the 3rd row of the matrix.
Is there anyway I could do this?
Thank you.
0 件のコメント
採用された回答
Atsushi Ueno
2021 年 12 月 5 日
A = [1 2 3; 4 5 6; 1 2 3; 1 2 3]
diff(A,1)
replace_row = [false; ~all(diff(A,1),2)]
A(replace_row, :) = 0
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!