How to delete empty rows in a cell array?

7 views (last 30 days)
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
Jan
Jan on 25 Feb 2021
If would help if you provide some input data. "empty or 'missing value'" are two different things. It is not clear, which of them is required. Is it a cell string, string array or a cell matrix? Where does the screenshot come from? Is this Matlab?
It helps if you post what you have tried already and explain, why this does not satisfies your needs. This would reduce the chance to spend time for writing in an answer, what you have tried already.
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
Haron Shaker
Haron Shaker on 25 Feb 2021
Hi Rik,
This does not work.
Reading the .xls file with readcell, fills the empty rows with '1x1 missing' ( see screenshot). Any idea how I can delete them?
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)

Categories

Find more on Data Type Conversion 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!