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!