separate empty cells (NaN) from others

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 日

1 投票

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 件のコメント

Amr Hashem
Amr Hashem 2015 年 7 月 25 日
I try it, but it gives me an error :
??? Error using ==> cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
Error in ==> remove_nan at 10
id12=~cellfun(@isnan,c12)
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 25 日
Can you precise if your cell are Nan or empty? if they are empty then the code changes
c12=A(:,12)
id12=~cellfun(@isempty,c12)
out=A(id12,:)
Amr Hashem
Amr Hashem 2015 年 7 月 25 日
in excel they were empty but after open in matlab they convereted to NaN
here is an example of the cells of column 12 are:
'12\02\2014'
'12\02\2014'
NaN
when i try :
id12=~cellfun(@isnan,c12) % it gives me error
and when trying:
id12=~cellfun(@isempty,c12) % it didn't separate the NaN row
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 件)

カテゴリ

ヘルプ センター および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by