How to delete empty rows in a cell array?

조회 수: 38 (최근 30일)
Haron Shaker
Haron Shaker 2021년 2월 25일
댓글: Rik 2021년 2월 25일
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
Jan
Jan 2021년 2월 25일
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 2021년 2월 25일
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'.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2021년 2월 25일
empty = cellfun('isempty', C);
C(empty) = [];
  댓글 수: 3
Haron Shaker
Haron Shaker 2021년 2월 25일
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 2021년 2월 25일
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개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by