# How can I delete the rows of a matrix in matlab under a given condition

9 views (last 30 days)
Sky Scrapper on 14 Nov 2018
Edited: madhan ravi on 23 Nov 2018
Hello everybody,
I have a matrix which has 10118 rows and 14 columns. I would like to delete the number of rows having values greater than 100. How can I do this?
Thanks in advance!
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

madhan ravi on 14 Nov 2018
Edited: madhan ravi on 23 Nov 2018
EDITED
%Numbers greater than 100
idx = matrix > 100;
matrix ( ~ ( sum ( idx , 2) == 0 ) , : ) = []
%__________________________
%Numbers lesser than 100
idx = matrix < 100;
matrix ( sum ( idx , 2 ) ~= 0 , : ) = []
##### 21 CommentsShowHide 20 older comments
madhan ravi on 23 Nov 2018
Edited: madhan ravi on 23 Nov 2018
@Skyscraper: yes because if any of the numbers in a matrix is less than 100 the whole row is removed, the matrix which you gave contains numbers less than 100 in each row.

Sign in to comment.

### More Answers (1)

Stephen23 on 23 Nov 2018
Edited: Stephen23 on 23 Nov 2018
@Sky Scrapper: the standard MATLAB practice is to use any:
>> A = [110,0,10,70,15;100,30,50,20,9;50,-150,95,65,7]
A =
110 0 10 70 15
100 30 50 20 9
50 -150 95 65 7
>> B = A(~any(abs(A)>100,2),:) % create a new array B,
B =
100 30 50 20 9
>> A(any(abs(A)>100,2),:) = [] % or delete rows from A.
A =
100 30 50 20 9
##### 1 CommentShowHide None
Sky Scrapper on 23 Nov 2018
Yes, it's working properly. Thank you very much for your help!

Sign in to comment.

### Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by