MATLAB Answers

remove the rows of matrix?

1 view (last 30 days)
jack nn
jack nn on 1 Apr 2015
Commented: jack nn on 1 Apr 2015
I want to remove the rows of matrix that the value of them in first column is zero...I use this code:
if true
for i=1:7
if m(i)==0
m(i,:)=[];
i=i-1;
end
end
end
I run this code for this matrix but the answer is not true,it could not remove all rows that the first column of them is zero..
if true
>> m=[1 2;3 4;0 5;3 0;0 4;0 54;3 22]
m =
1 2
3 4
0 5
3 0
0 4
0 54
3 22
if true
>> for i=1:7
if m(i)==0
m(i,:)=[];
i=i-1;
end
end
end
but when we saw the result,the result is: >> m
m =
1 2
3 4
3 0
0 54
3 22
end
is my cod wrong?

  0 Comments

Sign in to comment.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 1 Apr 2015
Edited: Azzi Abdelmalek on 1 Apr 2015
m=[1 2;3 4;0 5;3 0;0 4;0 54;3 22]
m(~m(:,1),:)=[]

  1 Comment

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags