Cody Problem 25. Remove any row in which a NaN appears
1 次查看(过去 30 天)
显示 更早的评论
function B = remove_nan_rows(A)
[x,y]=size(A)
[row, col] = find(isnan(A))
B=[];
for i=1:x
if (i ~=row)
B=[B ;A(i,:)]
end
end
for A=1:10, the algorithm didn't work, can someone help me with figuring out what's wrong.
Thanks in advance!
3 个评论
DGM
2021-4-9
Consider that isnan(A) returns a logical array, and that any() can work along a specified direction.
B = A(~any(isnan(A),2),:);
or something like that.
采纳的回答
DGM
2021-4-9
Okay.
Consider that isnan(A) returns a logical array, and that any() can work along a specified direction.
B = A(~any(isnan(A),2),:);
or something like that.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!