how to search a cell array for a row of empty character cells in matlab

To search a cell array for a row of empty character cells in MATLAB, you can use the all function and isempty function in combination. Here's an example:

main.m
% create a sample cell array
cellArray = {'', '', ''; 'foo', '', 'bar'; '', 'baz', ''};

% loop through the rows of the cell array
for i = 1:size(cellArray, 1)
    % check if all cells in the row are empty
    if all(cellfun(@isempty, cellArray(i,:)))
        disp(['Row ', num2str(i), ' is empty']);
    end
end
313 chars
11 lines

This code creates a sample cell array, then loops through the rows of the array using a for loop. For each row, it uses cellfun to check if every cell in the row is empty using the isempty function. If all cells are empty, the row number is printed to the console.

You could modify this code to do something else when an empty row is found, such as removing the row from the cell array or marking it for later processing.

gistlibby LogSnag