필터 지우기
필터 지우기

Trying to do mesh in MatLab but get NaN ?

조회 수: 2 (최근 30일)
Mark
Mark 2012년 8월 1일
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.

채택된 답변

Walter Roberson
Walter Roberson 2012년 8월 1일
Qi = 1 + exp(-ei ./ Ti);

추가 답변 (1개)

Star Strider
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
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by