MATLAB Answers

Removing elements from matrix

60 views (last 30 days)
Marin on 14 May 2012
Commented: Julia on 5 Aug 2014
Hi everyone,
I was wonderning is there an easy way to remove some of the elemetts from matrix. I have a data array data(300x2) and I want to remove all rows that have the value in the second column smaller than 0.18.
I tried something like
and similar combinations but it doesn't work.
Thank you in advance for any advice you can offer.


harsha on 5 Aug 2014
i have a 49x49 matrix and i want to delete the single element at center of the can i do so?please help.
Julia on 5 Aug 2014
What do you mean with delete? Set to 0? You can delete the row or the column containing the element, but you cannot create a hole in the middle of the matrix.

Sign in to comment.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 14 May 2012
ADDED after Marin's comment
simple example
data1 =[...
2 3
5 8
10 3
4 6
6 7]
data2 =[...
9 2
10 2
6 3]
data1(ismember(data1(:),data2(:))) = nan

  1 Comment

Marin on 14 May 2012
yeah, of course, now I see I could have solved it myself, but I've been too hasty. :)
thank you very much :)
another thing, if you can help me also.
if I have two data sets data1(300x2) and data2(50x2) and data2 contains elements that are in data1 (of course not all of them).
how do I create a matrix which has the data that is in data1 and not in data2 ?

Sign in to comment.

More Answers (1)

Marin on 15 May 2012
Excellent. Thank you!


Sign in to comment.

Sign in to answer this question.