remove the NaN numbers from a matrix without loop
이전 댓글 표시
Hello Matlab Users,
In my matrix of NxD dimension, I know that the number of NaNs on each row are the same, however the position of these NaN elements differ between rows. Is there an efficient way to remove NaN's from this matrix while keeping the shape of matrix, as shown in the simplified example:
A=[ 1 2 3 NaN 4 5 NaN; 6 NaN 7 8 NaN 9 10]
and I would like to be able to remove NaNs and get:
A_mod=[ 1 2 3 4 5; 6 7 8 9 10]
I appreciate your help, NF
채택된 답변
추가 답변 (1개)
bym
2011년 11월 28일
A_mod = A(~isnan(A)); %untested
댓글 수: 3
Walter Roberson
2011년 11월 28일
No, that will not maintain the number of rows, and does not get the elements in the right position to be reshape()'d in to rows.
bym
2011년 11월 28일
right
Noushin Farnoud
2011년 11월 29일
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!