add lsline or trend line to log-log graph
조회 수: 10 (최근 30일)
이전 댓글 표시
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
채택된 답변
Star Strider
2015년 3월 8일
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
Star Strider
2015년 3월 14일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!