Removing elements from matrix

조회 수: 2 (최근 30일)
Marin
Marin 2012년 5월 14일
댓글: Julia 2014년 8월 5일
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
data=data(data(:,2)<0.18);
and similar combinations but it doesn't work.
Thank you in advance for any advice you can offer.
  댓글 수: 2
harsha
harsha 2014년 8월 5일
hi
i have a 49x49 matrix and i want to delete the single element at center of the matrix.how can i do so?please help.
Julia
Julia 2014년 8월 5일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 5월 14일
data=data(data(:,2)>=0.18,:);
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
Marin
Marin 2012년 5월 14일
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 ?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Marin
Marin 2012년 5월 15일
Excellent. Thank you!

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by