add lsline or trend line to log-log graph
11 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Star Strider
on 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:
12 Comments
Star Strider
on 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.
More Answers (0)
See Also
Categories
Find more on Red in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!