필터 지우기
필터 지우기

separate empty cells (NaN) from others

조회 수: 1 (최근 30일)
Amr Hashem
Amr Hashem 2015년 7월 25일
댓글: Amr Hashem 2015년 7월 25일
I have a table of cells ( ex: 100*75 cell)
and i want to focus on column 12 , if any cell in it is NaN (empty) , i want to separate its row from the table.
i use this code:
[ndata text alldata] = xlsread('mdr1.xls','sheet1');
[R1,C1]=size(alldata);
j=1;
K=1;
for i=1:size(alldata,1)
if isnan(alldata{i,12})
Ndate(j)=i;
j=j+1;
else
Ydate(K)=i;
K=K+1;
end
end
NAdate=alldata(Ndate,:);
DDate=alldata(Ydate,:);
xlswrite('separate.xls',DDate,1);
xlswrite('separate.xls',NADate,2);
it works...
but
I wonder if anyone has an idea to modify this code.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 25일
편집: Azzi Abdelmalek 2015년 7월 25일
If A is your cell array
c12=A(:,12)
id12=~cellfun(@isnan,c12)
out=A(id12,:)
If you want the part containing nan
out1=A(~id12,:)
  댓글 수: 5
Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 25일
편집: Azzi Abdelmalek 2015년 7월 25일
Ok, try this
id12=~cellfun(@(x) all(isnan(x)),c12)
Amr Hashem
Amr Hashem 2015년 7월 25일
thanks. جزاكم الله خيرا
it works ...

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

추가 답변 (0개)

카테고리

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