Borrar filtros
Borrar filtros

Can I replace the row of the matrix when its value is equal to the previous row?

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Atsushi Ueno
Atsushi Ueno el 5 de Dic. de 2021
A = [1 2 3; 4 5 6; 1 2 3; 1 2 3]
A = 4×3
1 2 3 4 5 6 1 2 3 1 2 3
diff(A,1)
ans = 3×3
3 3 3 -3 -3 -3 0 0 0
replace_row = [false; ~all(diff(A,1),2)]
replace_row = 4×1 logical array
0 0 0 1
A(replace_row, :) = 0
A = 4×3
1 2 3 4 5 6 1 2 3 0 0 0

Más respuestas (0)

Categorías

Más información sobre Multidimensional Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by