MATLAB Answers

Naime
0

omit zeros from matrix and have the shape of matrix

Asked by Naime
on 14 Apr 2019
Latest activity Answered by Kevin Rawson on 14 Apr 2019
A=[0,0;0,0;0,0;1,2;2,5;5,7;7,8];
I want to omit zero from this matrix. result should be
New_A=[1,2;2,5;5,7;7,8];
I use this code
A(A==0) = [];
But giving me array.

  0 Comments

Sign in to comment.

1 Answer

Answer by Kevin Rawson on 14 Apr 2019
 Accepted Answer

If you are trying to get rid of rows with zeros:
A(all(A == 0, 2), :) = [];

  0 Comments

Sign in to comment.