MATLAB: How to mark the rows which don’t have an empty value in a certain column and store this rows in a new variable

empty valuestore in new variable

I have a cell array with 1000×13 cells. I now want to get every row which does have a value in column 12 and store them in a new variable. Till now I ve been trying to somehow get around with the "isempty' function and wanted to distract that from the original cell array, but I got stuck and I m aware of that not being the most elegant way to do it… So someone might help out? Thanks in advance!
X=data
for i= 2:10000
column= X(:,12)
column_empty = column(~cellfun(@isempty, column))

Best Answer

idx = cellfun(@(C) size(C,2) >= 12, data);
cells_with_12 = data(idx);
Note that the result will be a column array.
Or did you mean each cell row which has a non-empty element for cell column 12?
idx = ~cellfun(@isempty, data(:,12));
rows_with_12 = data(idx,:);