- 0 / 0
- Inf / Inf
- 0 * Inf
- Inf - Inf or similar operation
NaN issue when calculating for a mean value
14 ビュー (過去 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!