How to get rid of "negative data ignored" warning in a loglog plot
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Avishek Mukherjee
le 20 Mai 2021
Commenté : Avishek Mukherjee
le 20 Mai 2021
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 commentaires
Réponse acceptée
Image Analyst
le 20 Mai 2021
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 commentaires
Plus de réponses (1)
Sulaymon Eshkabilov
le 20 Mai 2021
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-')
Voir également
Catégories
En savoir plus sur Correlation Models dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
