Find the index of zero in cell and put it as empty

8 ビュー (過去 30 日間)
NA
NA 2020 年 1 月 7 日
コメント済み: NA 2020 年 1 月 8 日
A={[45;101],[2;7],[5;8],0,0};
A(cell2mat(A)==0)={[]}; % I want to find zero and put in empty
A should be
A={[45;101],[2;7],[5;8],[],[]};

採用された回答

Guillaume
Guillaume 2020 年 1 月 7 日
編集済み: Guillaume 2020 年 1 月 7 日
A(cellfun(@(x) isequal(x, 0), A)) = {[]}; %replace any cell whose content is the scalar 0 by empty
is one way.
edit: fixed code.
  6 件のコメント
Guillaume
Guillaume 2020 年 1 月 7 日
Do'h! I knew this was simple. Thanks, Stephen. For some reason, I had it in my head that {} and {[]} were the same thing.
NA
NA 2020 年 1 月 8 日
Thanks Stephen.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by