From: Pallab Ghosh on
Hi All,

I have a very simple problem. Please help me:

Say X=[ 12 0; 45 1; 34 1 ; 67 0; 89 1];

The second column consists of binary number. I want to delete the entire rows of X when the second column of X is 0.

so my output would be: X=[ 45 1
34 1
89 1]

May be there are no keep or delete function in MATLAB so I don't know the syntax to delete rows using if condition.

Karna Sakara
(Student)
From: Chris on
X=[ 12 0; 45 1; 34 1 ; 67 0; 89 1];
K=find(X(:,2)==0);
P=removerows(X,K);


"Pallab Ghosh" <karna.sakara(a)gmail.com> wrote in message <i3uj6q$j4$1(a)fred.mathworks.com>...
> Hi All,
>
> I have a very simple problem. Please help me:
>
> Say X=[ 12 0; 45 1; 34 1 ; 67 0; 89 1];
>
> The second column consists of binary number. I want to delete the entire rows of X when the second column of X is 0.
>
> so my output would be: X=[ 45 1
> 34 1
> 89 1]
>
> May be there are no keep or delete function in MATLAB so I don't know the syntax to delete rows using if condition.
>
> Karna Sakara
> (Student)
From: Jan Simon on
Dear Pallab,

> I have a very simple problem. Please help me:
> Say X=[ 12 0; 45 1; 34 1 ; 67 0; 89 1];
> The second column consists of binary number. I want to delete the entire rows of X when the second column of X is 0.

X(X(:, 2) == 0) = [];
or
X = X(X(:, 2) ~= 0);

There is the "Getting started" section in the documentation. There you find an exhaustive and descriptive help for such questions.

Kind regards and welcome to Matlab, Jan
From: Matt Fig on
"Chris " <apopheniotic(a)gmail.com> wrote in message <i3ukcj$gtu$1(a)fred.mathworks.com>...
> X=[ 12 0; 45 1; 34 1 ; 67 0; 89 1];
> K=find(X(:,2)==0);
> P=removerows(X,K);


There is no need for FIND.

X = X(logical(X(:,2)),:)
From: Pallab Ghosh on
Thank you Matt.



"Matt Fig" <spamanon(a)yahoo.com> wrote in message <i3ul48$4tn$1(a)fred.mathworks.com>...
> "Chris " <apopheniotic(a)gmail.com> wrote in message <i3ukcj$gtu$1(a)fred.mathworks.com>...
> > X=[ 12 0; 45 1; 34 1 ; 67 0; 89 1];
> > K=find(X(:,2)==0);
> > P=removerows(X,K);
>
>
> There is no need for FIND.
>
> X = X(logical(X(:,2)),:)