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!
  2 Comments
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
Jan on 25 Feb 2021
empty = cellfun('isempty', C);
C(empty) = [];
  3 Comments
Rik
Rik on 25 Feb 2021
This is so similar to Jan's answer that I'm going to post it as a comment:
C=readcell('founded_medicine_folder.xls');
empty = cellfun('isclass', C, 'missing');
C(empty) = [];
celldisp(C)
C{1} = https:/www.isip.piconepress.com/projects/tuh_eeg/downloads/tuh_eeg/v1.1.0/edf/01_tcp_ar/085/00008530/s001_2012_01_04/ C{2} = https:/www.isip.piconepress.com/projects/tuh_eeg/downloads/tuh_eeg_abnormal/v2.0.0/edf/train/normal/01_tcp_ar/085/00008530/s001_2012_01_04/ C{3} = https:/www.isip.piconepress.com/projects/tuh_eeg/downloads/tuh_eeg_artifact/v1.0.0/edf/01_tcp_ar/085/00008530/s001_2012_01_04/ C{4} = https:/www.isip.piconepress.com/projects/tuh_eeg/downloads/tuh_eeg/v1.2.0/edf/01_tcp_ar/146/00014654/s001_2016_07_19/

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!