Can I replace the row of the matrix when its value is equal to the previous row?
    5 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Chang seok Ma
 il 5 Dic 2021
  
    
    
    
    
    Risposto: Atsushi Ueno
      
 il 5 Dic 2021
            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 Commenti
Risposta accettata
  Atsushi Ueno
      
 il 5 Dic 2021
        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 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Cell Arrays in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!