delete zeros in cell array

4 ビュー (過去 30 日間)
Elysi Cochin
Elysi Cochin 2021 年 4 月 13 日
コメント済み: Elysi Cochin 2021 年 4 月 14 日
i have a cell_array with values
cellarr = {'b','a','a','a','b';0,'c',0,'b',[];0,'a',0,'d',0;'a','a','b',[],[]};
i wanted to delete the zeros in the cell_array so as to get the new cell array as below
shift the remaining columns to left after deleting the zero
new_cellarr = {'b','a','a','a','b';'c','b',[],[],[];'a','d',[],[],[];'a','a','b',[],[]};
  1 件のコメント
madhan ravi
madhan ravi 2021 年 4 月 13 日
I think what you are describing is not what show in the expected result.

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

採用された回答

Matt J
Matt J 2021 年 4 月 13 日
Using the attached file sortlidx.m,
cellarr = {'b','a','a','a','b';0,'c',0,'b',[];0,'a',0,'d',0;'a','a','b',[],[]}
cellarr = 4×5 cell array
{'b'} {'a'} {'a'} {'a' } {'b' } {[0]} {'c'} {[0]} {'b' } {0×0 double} {[0]} {'a'} {[0]} {'d' } {[ 0]} {'a'} {'a'} {'b'} {0×0 double} {0×0 double}
map=cellfun(@isnumeric,cellarr);
cellarr(map)={[]};
[~,isort]=sortlidx( ~map ,2,'descend');
cellarr = cellarr(isort)
cellarr = 4×5 cell array
{'b'} {'a'} {'a' } {'a' } {'b' } {'c'} {'b'} {0×0 double} {0×0 double} {0×0 double} {'a'} {'d'} {0×0 double} {0×0 double} {0×0 double} {'a'} {'a'} {'b' } {0×0 double} {0×0 double}
  1 件のコメント
Elysi Cochin
Elysi Cochin 2021 年 4 月 14 日
Superb Sir

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by