MATLAB Answers

How to delete empty rows in a cell array?

4 views (last 30 days)
Haron Shaker
Haron Shaker on 25 Feb 2021
Commented: Rik on 25 Feb 2021
Hello guys,
I want to delete all rows in a cell array which are empty, respectively where it says 'missing value'. I tried several functions but did not get the desired result.
I attached a screenshot for you to get an idea.
Thanks in advance!
Haron Shaker
Haron Shaker on 25 Feb 2021
Hi Jan ,
thanks for your answer.
I am using Matlab. I got an cell array, saved as .xls. Opening this file I get a 7x1 cell array (see founded_medicine_folder.xls), where three of the rows are empty. That is, I want to get an 4x1 array, without the empty ones.
I wrote both, "empty or 'missing value'", because reading the file with readcell() fills the empty rows with '1x1 missing'.

Sign in to comment.

Accepted Answer

Jan on 25 Feb 2021
empty = cellfun('isempty', C);
C(empty) = [];
Rik on 25 Feb 2021
This is so similar to Jan's answer that I'm going to post it as a comment:
empty = cellfun('isclass', C, 'missing');
C(empty) = [];
C{1} = https:/ C{2} = https:/ C{3} = https:/ C{4} = https:/

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!