Info
此问题已关闭。 请重新打开它进行编辑或回答。
Erase all the rows that contain NaN
1 次查看(过去 30 天)
显示 更早的评论
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 个)
Miro
2012-7-18
编辑:Miro
2012-7-18
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 个评论
Miro
2012-7-18
编辑:Miro
2012-7-18
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.
Jan
2012-7-18
Perhaps something like this:
index = cellfun(@isequalwithequalnans, R, {NaN});
R(all(index, 2)) = [];
But due to a vague defined input, this contains too much guessing to be reliable. Sorry.
1 个评论
Andrei Bobrov
2012-7-18
Rout = R(~all(cellfun(@(x)all(isnan(x)),R),2),:)
4 个评论
Jan
2012-7-18
@Sabbas: Do you get a "warning" or an "error"? In both cases posting the message would be a good idea.
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!