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

8 vues (au cours des 30 derniers jours)
NA
NA le 7 Jan 2020
Commenté : NA le 8 Jan 2020
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],[],[]};

Réponse acceptée

Guillaume
Guillaume le 7 Jan 2020
Modifié(e) : Guillaume le 7 Jan 2020
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 commentaires
Guillaume
Guillaume le 7 Jan 2020
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 le 8 Jan 2020
Thanks Stephen.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by