getting rid of empty cells in a cell array

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!

 Risposta accettata

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)

Più risposte (1)

Mischa Kim
Mischa Kim il 15 Gen 2014
Modificato: Mischa Kim il 15 Gen 2014
Try y=x(~cellfun('isempty',x))

4 Commenti

thanks, this helps me as well...
Thank you . How do I extend this to work for a n-d cell array
I have the same question above, how to apply this to a specific row or colums.
Yes, same query

Accedi per commentare.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by