필터 지우기
필터 지우기

getting rid of empty cells in a cell array

조회 수: 39 (최근 30일)
Sebastiano delre
Sebastiano delre 2014년 1월 15일
댓글: Nisha Bharti 2021년 10월 10일
Hi,
can you please help me with this? I have the following cell array
x = {1,[],'ciao',[],[]};
I want to exclude the empty cells, and get another array like this:
y = {1,'ciao'};
Thank you!

채택된 답변

Niklas Nylén
Niklas Nylén 2014년 1월 15일
First, check which cells that are empty using the function isempty. Since isempty does not accept cell arrays as input, you can use the cellfun function. This will call a function with each element of a cell array:
index = cellfun(@isempty, x) == 0;
y = x(index)

추가 답변 (1개)

Mischa Kim
Mischa Kim 2014년 1월 15일
편집: Mischa Kim 2014년 1월 15일
Try y=x(~cellfun('isempty',x))
  댓글 수: 4
Yiqian Qian
Yiqian Qian 2021년 5월 27일
I have the same question above, how to apply this to a specific row or colums.
Nisha Bharti
Nisha Bharti 2021년 10월 10일
Yes, same query

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by