Semilog plot that includes curve fit
조회 수: 43 (최근 30일)
이전 댓글 표시
I have used the curve fitting app to generate code to plot the data and the curve fit. I am new to MatLab but it looks like the relevant line of code is:
h = plot( fitresult, xData, yData );
This generates a plot with the data and curve.
However, I want a semilog plot. So I tried;
h = semilogx(xData, yData,'o');
which generates a semilog plot of the data points WITHOUT the fitted curve. When I try the following I get an error:
h = semilogx(fitresult, xData, yData,'o');
It looks like the plot function allows the "fitresult" to be added in a single line, but semilogx does not. Is that correct?
How do I add the fitted curve to the semilog plot?
댓글 수: 0
채택된 답변
Dave B
2021년 11월 13일
편집: Dave B
2021년 11월 13일
It turns out that semilogx is a shortcut for plot and setting the XScale property on the axes. So you can just do:
plot(fitresult, xData, yData, 'o')
set(gca, 'XScale', 'log')
(Maybe this is obvious, but just in case, this just affects how the data are plotted not how the fit is applied...if you want to fit some data logarithmically you might consider transforming xData before fitting, plotting linearly, and modifying the ticks/ticklabels.)
댓글 수: 3
Dave B
2021년 11월 13일
편집: Dave B
2021년 11월 13일
If you use the fit() function (which what the tool generates when you generate code?) then it's in the second output, documented as gof here: https://www.mathworks.com/help/curvefit/fit.html
load census
f=fit(cdate,pop,'poly2');
[f,gof]=fit(cdate,pop,'poly2');
gof.rsquare
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!