Search code examples
matlabcell-arrayis-empty

How to find empty array in a cell array in matlab?


My data has the following structure:

Cell_Array = {{[1]},{[]},{[8]}};

How can I find the empty array in this cell array without making a double loop?

This does not work. Since everything is not empty in this cell array.

~cellfun(@isempty,Cell_Array(:))

As you can see here:

isempty(Cell_Array{1,2})
ans = 0

It only works if:

isempty(Cell_Array{1,2}{1,1})
ans = 1

How can I solve this elegantly with cellfun?


Solution

  • This works without relying on the array having a specific structure. It gives a logical index with true for cells that contain {[]} and false for other cells.

    result = cellfun(@(x)isequal(x,{[]}), Cell_Array);