Remove all zeros from a matrix

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

7 件のコメント

Torsten
Torsten 2022 年 6 月 23 日
If you remove the zeros, you must replace them by something in order to leave the structure of the matrix unchanged.
Rohit Kulkarni
Rohit Kulkarni 2022 年 6 月 23 日
You can skip that column in the for-loop.
Rik
Rik 2022 年 6 月 23 日
Exact terms matter for your question. Is your data stored in a cell array, or in a (double) matrix?
Rik
Rik 2022 年 6 月 24 日
Comment posted as flag by @Moritz Nusser:
The data is stored in a double matrix
Rik
Rik 2022 年 6 月 24 日
In that case, Torsten gave you the answer: a double array cannot have empty elements, only cell arrays can.
Rik
Rik 2022 年 6 月 24 日
Comments psted as flags by @Moritz Nusser (please don't use flags to post comments, they are meant to attract the attention of site admins):
ok, so which kind of removement would you choose so that the "for-loop" won't create error mistakes ?
Thank your for your fast response ! Is it possible to use cell arrays for calculations in a for loop ?
Rik
Rik 2022 年 6 月 24 日
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.

サインインしてコメントする。

回答 (1 件)

Karan Kannoujiya
Karan Kannoujiya 2022 年 6 月 24 日

0 投票

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
link-->

1 件のコメント

Adam Danz
Adam Danz 2022 年 6 月 24 日
Note that column 5 of the image in the question contains all 0s so this proposal would potentially eliminate all of the data.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2022 年 6 月 23 日

コメント済み:

2022 年 6 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by