% CELLLENGTH - return the lengths of all elements in a cell (up to 2D cell array)

function lengths = celllength(x)
    
    if ~iscell(x) || length(size(x)) > 2
        error('celllength only works on up to 2D cell arrays');
    end
    
    lengths = NaN * ones(size(x));
    
    for i=1:size(x,1)
        for j=1:size(x,2)
            lengths(i,j) = length(x{i,j});
        end
    end


