How to delete empty rows in a cell array?

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 个评论

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.
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'.

请先登录,再进行评论。

 采纳的回答

empty = cellfun('isempty', C);
C(empty) = [];

3 个评论

@Haron Shaker Note that this solution might not work depending on your exact data type. This syntax will be extremely fast, but you will need to switch to the code below for some data types.
empty = cellfun(@isempty, C);
C(empty) = [];
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?
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/

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by