MATLAB Answers

How to handle NAN when summing

3 views (last 30 days)
I have the following code:
for k = 1:N
Fluor(i,k)= cB(i,k)*W(i,k)*dx;
FL = sum(Fluor(i,1:N),'all');
Sometimes cB(i,k) is equal to zero and because W2 is a negative number this, I guess, ultimately results in Fluor (i,k) equal to NaN. Is there a way to have Matlab insert zero instead of NaN for Fluor(i,k). Ultimately, I'm interested in FL, so an alternative might be to have Matlab skip any values of NaN when summing the row in table Fluor.

More Answers (0)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!