Erase all the rows that contain NaN
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
Dear all
I have
[N,T,R]=xlsread(name)
I want to erase all the rows in R that contain only NaN
thanks
[EDITED, copied from comments]:
So to input cell matrix is
'TOTPAIN' [NaN] [6.9150]
[1x40 char] [NaN] [6.90]
[ NaN] [NaN] [NaN]
[ NaN] [NaN] [NaN]
'MAS' [NaN] [NaN]
'MAR PACK G' [NaN] [6.7]
'MA 3 PACK 58G' [NaN] [6.7]
0 件のコメント
回答 (3 件)
hi,
try this
[n,~]=size(R)
R_new = [];
for i = 1 : n
R_tmp = R(i,:);
if length(find(isnan(R_tmp)) ~= length(R_tmp)
R_new = [R_new;R_tmp]
end
end
7 件のコメント
Sabbas
2012 年 7 月 18 日
Sabbas
2012 年 7 月 18 日
Jan
2012 年 7 月 18 日
@Sabbas: Instead of reminding, it would be helpful if you explain such important details at first. Let me remind you, that the function xrsread is not a common function with known output. Do you mean xlsread?
sorry for the missunderstanding. the following should work Your example looks like you want to delete the Coloumn, not the Row... For deleting the column try the following:
function Rout = deleteNAN(Rin)
[~,n]=size(R)
R_new = {};
for i = 1 : n
R_tmp = cell2mat(R(:,i));
if length(find(isnan(R_tmp))) ~= length(R_tmp)
R_new = [R_new R_tmp]
end
end
Rout = R_new
Store this in a .m file in your current folder and run it.
Andrei Bobrov
2012 年 7 月 18 日
Rout = R(~all(cellfun(@(x)all(isnan(x)),R),2),:)
4 件のコメント
Sabbas
2012 年 7 月 18 日
Andrei Bobrov
2012 年 7 月 18 日
編集済み: Andrei Bobrov
2012 年 7 月 18 日
R = {...
'TOTPAIN' [NaN] [6.915]
'hfffgfjfjgfj' [NaN] [ 6.9]
[ NaN] [NaN] [ NaN]
[ NaN] [NaN] [ NaN]
'MAS' [NaN] [ NaN]
'MAR PACK G' [NaN] [ 6.7]
'MA 3 PACK 58G' [NaN] [ 6.7]};
>> Rout = R(~all(cellfun(@(x)all(isnan(x)),R),2),:)
Rout =
'TOTPAIN' [NaN] [6.915]
'hfffgfjfjgfj' [NaN] [ 6.9]
'MAS' [NaN] [ NaN]
'MAR PACK G' [NaN] [ 6.7]
'MA 3 PACK 58G' [NaN] [ 6.7]
>>
Jan
2012 年 7 月 18 日
@Sabbas: Do you get a "warning" or an "error"? In both cases posting the message would be a good idea.
Sabbas
2012 年 7 月 20 日
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!