Find all the empty cells?

Suppose I have a cell array which looks like this:

C =
[] [] []
[] [] [3x3 double]
[] [] []

How can I get all the empty cells using as few commands as possible? Well, the answer is …

cellfun(@isempty, C)

So, cellfun is a function that applies a function (isempty here) to each cell of a cell array (C here). If you enjoy general Matlab functions that implicitly apply to each element of an array (say, sqrt(M) does the square roots to all the elements of M), then you must also enjoy this cellfun function that applies an arbitrary function to each element of a cell array. Check it out!


2 Responses to “Find all the empty cells?”

  1. 1 Andrew July 30, 2008 at 1:12 pm

    Just what I needed. Embarrassed I didn’t think of it myself. Thanks!

  2. 2 Fahim May 19, 2010 at 9:03 pm

    Very Nice Solution!!! Thanks

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


Blog Stats

  • 254,469 hits

%d bloggers like this: