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에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!