Remove all zeros from a matrix

1 view (last 30 days)
Moritz Nusser
Moritz Nusser on 23 Jun 2022
Commented: Adam Danz on 24 Jun 2022
I want to remove all zeros from cells a matrix, so i can use it in a for-loop later on. The structure of the matrix should not change after the zeros are removed. So every row should stay the same, just without the zeros in the cells.
Right now the size of my matrix is 27895x5
Rik on 24 Jun 2022
If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks). That will teach you how to work with cell arrays.

Sign in to comment.

Answers (1)

Karan Kannoujiya
Karan Kannoujiya on 24 Jun 2022
Hi moritz,
If you want to remove zero from a cell then you will have remove that row also otherwise it will not remain a matrix structure.
for removing any row you can do--->
tableName(rowNumber,:)=[ ];
I would suggest you to go through this Matlab Onramp course it just an 2 hours course you will understand everything
  1 Comment
Adam Danz
Adam Danz on 24 Jun 2022
Note that column 5 of the image in the question contains all 0s so this proposal would potentially eliminate all of the data.

Sign in to comment.


Find more on Numeric Types in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!