MATLAB: Replacing NaN’s in column of a Matrix

if statementnan

Hello! I feel tihs should be rather simply but for some reason I cannot get it to work.
I have a 2922×14 matrix. In random places in the second column there are 'NaN' and I'm trying to change all the 'NaN' to 250. Im trying to do a possible if-else (or anything that should work) statement to change all the NaN in just that second column to 250. Thank you ahead of time for the help!

Best Answer

Where M is your matrix:
X = isnan(M(:,2));
M(X,2) = 250;