how to write an if statement for a matrix with some NaN elements?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello all,
I have a matrix with some elements 0s or 1s and the rest are NaNs. I would like to write an if statement that ignores the NaN elements of the matrix. I have tried
if (a(:)==1 or a(:)==0)
------------
end
however, I am getting an error. I would appreciate if somebody can help me please. Thanks.
답변 (1개)
Walter Roberson
2015년 5월 5일
nonnanlocs = ~isnan(a);
a(nonnanlocs) = SomeFunction(a(nonnanlocs));
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!