MATLAB: Replace NaN with specific value.

error catch with numberhandling nanMATLABreplacing nan with a number

I have many large column matrices (each is ~20k x 1). Some elements of the matrices are NaN. I want to replace them with 0 (or some number). Is there a quick way for that. Looping through each element is a very inefficient process and delays my program. The help is really appreciated.

Best Answer

yourmatrix(isnan(yourmatrix)) = somevalue;
But, using NaN to mark exceptional values is much better than using 0 or some other special value.