I have a cell array of n number of rows and one column. Each row contains an array.
I want to exclude these NaN cells or copy this cell array in a new one with skipping the NaN cells in the original.

 채택된 답변

Star Strider
Star Strider 2020년 9월 6일

0 개 추천

Try this:
fine_xx = {rand(10,1);rand(10,1);[];rand(10,1);[];[];rand(10,1)}
fine_xx = fine_xx(cellfun(@(x)~isempty(x), fine_xx))
That eliminiates the empty [] cells.

댓글 수: 2

Hazem Al-Bulqini
Hazem Al-Bulqini 2020년 9월 6일
The second line did the job, thank you.
Star Strider
Star Strider 2020년 9월 6일
As always, my pleasure!
(The first line was a test vector I used to be sure my code did what I wanted it to. My apologies for not labeling it as ‘% Test Vector’.)

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

추가 답변 (1개)

David Hill
David Hill 2020년 9월 6일
편집: David Hill 2020년 9월 6일

0 개 추천

c=[];
for k=1:length(yourCell)
if ~isempty(yourCell{k})
c=[c,k];
end
end
newCell=yourCell(c);

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

질문:

2020년 9월 6일

댓글:

2020년 9월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by