how to delete NaN from a function output

조회 수: 1 (최근 30일)
mcm
mcm 2016년 10월 17일
답변: Image Analyst 2016년 10월 17일
I Created a if function that will output a matrix with numeric values and NaN values. What should I add at the end of the function so that it will only display numeric values?

답변 (1개)

Image Analyst
Image Analyst 2016년 10월 17일
It would be best to remove the nan's from the array before you display it. And you forgot to say what line(s) of code you are using to display it (like fprintf or whatever).
To remove nans from an vector:
vec(isnan(vec)) = [];
vec will now be shorter if there were nans in it.
Unfortunately you can't remove nan's from a matrix because all rows and columns must be the same size -- you can't have "ragged" edges. The best you can do it to replace them with something, like 0 or -1 or whatever.
yourMatrix(isnan(yourMatrix)) = 0;

카테고리

Help CenterFile Exchange에서 NaNs에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by