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!