How to delete a row of a matrix if value in a particular column is less than a specified value?
    21 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Bobby Dow
 il 20 Feb 2017
  
    
    
    
    
    Commentato: Bobby Dow
 il 21 Feb 2017
            say I have a 3x4 matrix
data = [5 1 200 33; 3 0.5 100 33; 4.5 1.5 150 33]
I want to delete the entire row if the value in 1st column is less than 4.
it should return a 2x4 matrix looking like the following:
datanew = [5 1 200 33; 4.5 1.5 150 33]
I am going to apply this to a much larger matrix, like 10000x4 size, and think a loop is the way to go, but I am unsure on how to go about it.
Thanks Bob
0 Commenti
Risposta accettata
  John Chilleri
      
 il 20 Feb 2017
        
      Modificato: John Chilleri
      
 il 20 Feb 2017
  
      Hello,
You can use this one liner,
datanew = data(data(:,1)>=4,:);
However, I chose to reverse the logic here, so instead of less than 4, you should write greater than or equal to (it's selecting the ones to keep).
Also, the data(:,1) is using the first column (just to be clear).
Hope this helps!
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Loops and Conditional Statements 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!