Trying to do mesh in MatLab but get NaN ?
3 次查看(过去 30 天)
显示 更早的评论
I am trying to execute the following code:
T = 0:.1:12;
e = -6:.1:6;
[Ti,ei] = meshgrid(T,e);
Qi = 1 + exp(-ei/Ti);
However, Qi is giving me "NaN" in every single entry. Is there any way to fix that? Ti & ei can both be computed, but it does not seem to work when you do ei/Ti.
1 个评论
Walter Roberson
2012-8-12
Please retag this this this question; http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags
采纳的回答
更多回答(1 个)
Star Strider
2012-8-1
The way you have the ‘T’ and ‘e’ vectors defined, ‘T’ and ‘e’ will both be zero at some point. Where (-ei./Ti) = (0/0) you'll get NaN. Everything calculated from a vector or matrix with even one NaN value will generate NaN values for all of them. (This is apparently a standard.) The easiest solution is to redefine:
e = -6 : 0.11 : 6;
or
e = -6 : 0.09 : 6;
or something similar to prevent your ‘e’ vector becoming zero anywhere.
1 个评论
Walter Roberson
2012-8-1
Only positions whose value depend upon a term that is NaN, will become NaN.
The real problem in the code is that "ei' and "Ti" are vectors, and ei/Ti is a matrix right divide operation rather than an element-wise operation ei./Ti
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!