Reputation: 113
I have a cell matrix of size 248*15 with the maximum number of columns 15. I want to extract the rows containing greater than or equal to 8(>=8) non-zero column entries in MatLab.
For example: cell row 1,2,7,8,.....
Upvotes: 0
Views: 50
Reputation: 1139
You can use cellfun
to first determine which cell elements are empty, and then use array indexing to select the rows as required:
C = {} % The cell matrix of size 248 x 15.
% An array of 248 x 15 that has Booleans based on empty or not:
emptyCells = cellfun(@isempty, C)
% The total number of empty columns on each row:
emptyColsCount = sum(emptyCells, 2)
% Find those rows with at least 8 non-zero columns
requiredRowIndices = find(emptyColsCount < 8)
% This returns [1, 2, 7, ...]
Upvotes: 1