How to get rid of "negative data ignored" warning in a loglog plot
조회 수: 15 (최근 30일)
이전 댓글 표시
In fitting a least square line through a set of points on a loglog scale, MATLAB is returning the warning "Negative data ignored". For example,
N = [56 112 224 448 896 1792 3584 7168 14336];
T_max = [0.444793435182132 0.4395279003565365 0.43638330717684004 0.4344924804848505 ...
0.43374154539955007 0.43337438343040974 0.4331928605464643 ...
0.4331026128636092 0.4330576104805632];
T_min = [0.4172265675535062 0.42604231767208034 0.4304025036668112 ...
0.4317013137271798 0.4324741371494442 0.4328174950027687 ...
0.4329158371978752 0.4329426670435078 0.43298763322951783]
T_exact = 5*sqrt(3)*(0.1/2);
T_min_exact = abs(T_min - T_exact);
c2 = polyfit(N,T_min_exact,1);
y2 = polyval(c2,N);
loglog(N,T_min_exact, '*',N,y2,'R')
The above code produces the warning "Negative data ignored" and is producing the following plot:

How to overcome this problem and what am I doing wrong here?
댓글 수: 0
채택된 답변
Image Analyst
2021년 5월 20일
If you want to fit a line on the log-log plot, you'll have to take the log of x and log of y and fit that to a line. Then to display with loglog(), you'll have to "unlog" the line (exponentiate the fitted x and fitted y) to get it in the original space as the original data. You don't want to use loglog() on data that has already been logged!
Or better yet, use nlmfit(). I'm attaching several examples of nlmfit().
댓글 수: 3
추가 답변 (1개)
Sulaymon Eshkabilov
2021년 5월 20일
You had better select higher order of polynomial to fit or choose a different fit model, e.g., log function
...
c2 = polyfit(N,T_min_exact,8); % Order # 8.
y2 = polyval(c2,N);
loglog(N,T_min_exact, '*',N,y2,'r-')
참고 항목
카테고리
Help Center 및 File Exchange에서 Correlation Models에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
