How to Remove NaNs & INF From an Array in MATLAB


Unlike other programming languages that tend to deal with numbers and other types of input, such as words and paragraphs, MATLAB, a computer programming language created specifically for handling complex mathematical tasks., only works with numbers. If you have a non-number in an array -- a set of multiple values enclosed in brackets -- MATLAB prints it as "NaN" which is short for "Not a Number." MATLAB prints "infinity" as "INF." You can remove NaN and INF entries from an array with a simple command.

  • Launch MATLAB. Open the command line.

  • Assign your current array to a variable with the following code if it does not already have a variable:

    b = [ 0/1, 1, 0/0, 6 ]

    This becomes:

    b = [ INF, 1, NaN, 6 ]

  • Type the following code to remove the NaN and INF entries:

    b = b(finite(b))

Related Searches


Promoted By Zergnet


Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!