MATLAB: Is it possible to use the UNIQUE function with cell arrays containing empty cells in MATLAB 7.9 (R2009b)

MATLAB

When I try obtaining the unique members of a cell array that contains empty cells, I get the following error:
??? Error using ==> cell.unique at 47
Input must be a cell array of strings.

Best Answer

The ability to process empty cells directly with the UNIQUE function is not available in MATLAB 7.9 (R2009b).
As a workaround, you can identify which cells are not empty with the CELLFUN function:
c = {'hello', 'world', [], 'hello', 'MATLAB'}
~cellfun(@isempty, c)
Then use this logical array to index into the original cell array in order to call UNIQUE on only the elements of the cell array which are not empty:
unique(c(~cellfun(@isempty, c)))
Related Question