- 0 / 0
- Inf / Inf
- 0 * Inf
- Inf - Inf or similar operation
NaN issue when calculating for a mean value
조회 수: 13 (최근 30일)
이전 댓글 표시
gh = 0;
fg = 1;
mu_fg = MU_fib/fg;
adi = 1;
w = 0.042;
for ix = 1:200
for iy = 1:200
gh = gh + 1;
D = phi.*exp(MU_fat).*mu_fg.*((1-exp(-mewelement.*w))/mewelement).*((fg+adi)/adi).*(1/w);
meanD = sum(D)/60;
end
Above is a section of the program I am writing. This section has the goal of find the dose for each section of tissue. However, when i run it through, I get dose as NaN. I want the mean dose for the entire phantom as a single number.
Without the line meanD = sum(D)/60;, I get a matrix of 1 x 60 values which i don't want. I want one value for the dose (D).
Thank you. Any help is appreciated
댓글 수: 1
Guillaume
2020년 1월 23일
편집: Guillaume
2020년 1월 23일
Unfortunately, we don't know what MU_fib, MU_fat, phi and mwelement are, so can't test your code. You're getting NaN because one of your expression result in either
or one of your input is NaN already.
"I get a matrix of 1 x 60 values which i don't want" If you didn't expect a vector, then clearly you've got a bug. You'll get a vector if any of the above variables are a vector.
Note that as written, your loops overwrite meanD and D at each step, so you'll end up with just the value for ix = 200 and iy = 200 at the end.
답변 (1개)
Star Strider
2020년 1월 23일
The NaN result is due to one or more elements of the vector you are taking the mean of being (0/0) or (Inf/Inf), since they evaluate to NaN.
There are three options:
(1) Find and eliminate the source of the NaN elements
(3) use D(~isnan(D)) as the argument to mean in your present code.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!