Find a column number from a cell array

2 views (last 30 days)
I have a cell array from which I just know that some of its columns are "empty" and I would like to find those. For example I have an array:
C={1,'',6,11,''; 2,'',7,12,'';3,'',8,13,'';4,'',9,14,'';5,'',10,15,''}
And I would like my answers to be:
(meaning that 2nd and 5th columns are empty, the names for answer are not oblicatory but I would need them later on in my calculation)
Snowfall on 17 Feb 2016
Edited: Snowfall on 17 Feb 2016
Thank you for your answer. It helped me to think my application again so I did it in a different way.

Sign in to comment.

Accepted Answer

Guillaume on 9 Feb 2016
You need to apply the isempty function to each element of C to get a logical matrix. You can use an explicit loop or cellfun. It just then a matter of applying all to that logical matrix to find columns with all empty. Thus:
C = {1,'',6,11,''; 2,'',7,12,'';3,'',8,13,'';4,'',9,14,'';5,'',10,15,''};
emptycolumns = all(cellfun(@isempty, C))
%if you want the column number (often unnecessary, you can use the logical array directly)
emptycolumnsidx = find(emptycolumns)

More Answers (0)


Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!