how to check if a value is nan in matlab code example Example 1: if is nan matlab A(isnan(A))=1; Example 2: if is nan matlab if any(isnan(PMatrix), 'all')