How to handle NAN when summing

조회 수: 1 (최근 30일)
Robert Demyanovich
Robert Demyanovich 2021년 8월 19일
답변: Eric Sofen 2021년 8월 19일
I have the following code:
for k = 1:N
W(i,k)=W1*(cB(i,k))^W2;
Fluor(i,k)= cB(i,k)*W(i,k)*dx;
end
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.

채택된 답변

Eric Sofen
Eric Sofen 2021년 8월 19일
You can pass a flag to sum to 'omitnan'.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by