I had an idea to replace all the NaNs in my matrix by looping through each one and using isnan. However, I suspect this will make my code run more slowly than it should. Can
Let's say your matrix is:
A = NaN 1 6 3 5 NaN 4 NaN 2
You can find the NaN elements and replace them with zero using isnan like this :
NaN
A(isnan(A)) = 0;
Then your output will be:
A = 0 1 6 3 5 0 4 0 2