Search code examples
arraysmatlabcell-array

how find coordinates of cells


For example I have a:

1x11 cell
 [] []  3   []  []  []  []  []  1   []  []

How can I do to find coordinates of cells non empty?

like res=[1,3;1,9]


Solution

  • Apply the function isempty to each cell's contents via cellfun, and then get the column and row indices of the cells that gave false (that is, were not empty) using the two-output version of find:

    x = {[] []  3   []  []  []  []  []  1   []  []}
    [ii, jj] = find(~cellfun(@isempty, x))
    res = [ii(:) jj(:)];