![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/173736/image.png)
add lsline or trend line to log-log graph
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i want to draw a least square line to log-log plot i am using following scripy
wet=[120 49 30 21 12 10 9 7 4];
dry=[49 12 5 1 1 1 0 0 0 ];
x1=[1 2 3 4 5 6 7 8 9];
scatter(x1,wet);
set(gca,'XScale','log');
set(gca,'YScale','log');
lsline
but it is not working. is their any other way to draw a line which is straight pass through the points
0 commentaires
Réponse acceptée
Star Strider
le 8 Mar 2015
This works:
wet=[120 49 30 21 12 10 9 7 4];
dry=[49 12 5 1 1 1 0 0 0 ];
x1=[1 2 3 4 5 6 7 8 9];
scatter(x1,wet);
set(gca,'XScale','log');
set(gca,'YScale','log');
b = polyfit(log(x1), log(wet), 1);
wetfit = exp(b(2)) .* x1.^b(1);
hold on
plot(x1, wetfit)
hold off
producing:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/173736/image.png)
12 commentaires
Star Strider
le 14 Mar 2015
The code in the FEX contribution seems to use the same algorithm mine does for R-squared. Mine uses the nonlinear fit and the OLSCF (Ordinary Least Squares Cost Function) to generate the ‘norm(Y-X)’ data.
I didn’t run the FEX submission, but I trust my code.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Develop Apps Using App Designer 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!