Effacer les filtres
Effacer les filtres

getting rid of empty cells in a cell array

39 vues (au cours des 30 derniers jours)
Sebastiano delre
Sebastiano delre le 15 Jan 2014
Commenté : Nisha Bharti le 10 Oct 2021
Hi,
can you please help me with this? I have the following cell array
x = {1,[],'ciao',[],[]};
I want to exclude the empty cells, and get another array like this:
y = {1,'ciao'};
Thank you!

Réponse acceptée

Niklas Nylén
Niklas Nylén le 15 Jan 2014
First, check which cells that are empty using the function isempty. Since isempty does not accept cell arrays as input, you can use the cellfun function. This will call a function with each element of a cell array:
index = cellfun(@isempty, x) == 0;
y = x(index)

Plus de réponses (1)

Mischa Kim
Mischa Kim le 15 Jan 2014
Modifié(e) : Mischa Kim le 15 Jan 2014
Try y=x(~cellfun('isempty',x))
  4 commentaires
Yiqian Qian
Yiqian Qian le 27 Mai 2021
I have the same question above, how to apply this to a specific row or colums.
Nisha Bharti
Nisha Bharti le 10 Oct 2021
Yes, same query

Connectez-vous pour commenter.

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