MATLAB: Number of non nan observations

nan

Hi,
I have a matrix for which i need for each row to compute the number of non nan observations . such routine is occurring frequently in my program. I am wondering if it is possible to compute it without any loop. for example
0.81 0.10 NaN
0.91 NaN 0.97
0.91 NaN 0.97
NaN 0.55 0.96
0.91 0.96 0.49
NaN NaN NaN
is it possible to get [2;2;2;2;3;0] without running a loop?

Best Answer

sum(~isnan(In),2)