Can I get the best fit curve from the plot of many scattered points?
6 ビュー (過去 30 日間)
古いコメントを表示
Hi guys,
Do you know how can I make a fit curve from the plot of scattered points?. I need a fitted line with equation.
PS. I also attached the plot as I told you above.
Thanks in advance
3 件のコメント
John D'Errico
2016 年 10 月 25 日
編集済み: John D'Errico
2016 年 10 月 25 日
A fit to what? What shape do you expect? What model will you pose? Random numbers? Are you asking for something like a random distribution here? I suppose then you might decide to model this process as a (perhaps normal) distribution with a variance that depends on x.
Otherwise, the best fit to that data is, in my judgement, a constant. So just take the mean of your data in y. That is the least squares estimate of a constant function. Zero seems pretty close to me though.
回答 (2 件)
Yifan Men
2016 年 10 月 25 日
If you have the x and y data in the workspace, a quick way is to open the Curve Fitting App and set the x and y data. Then you will be able to choose the most common curve shape from the list and see which one best fits your data.
0 件のコメント
dpb
2016 年 10 月 25 日
Well, given the followup response, it's pretty simple to estimate the coefficients of a line given any set of data--of course, the results are going be residuals that look essentially the same as the values: but, maybe that's the desired result.
Given you have the data as x, y, then
ix=(x<1); % indices of the under-one x data
b=polyfit(x(ix),y(ix),1); % coefficients of a line for above data
As John notes, if you want to force a zero-slope line, then the least-squares estimate of the slope and intercept is simply
b=[0 mean(y(ix)]);
To evaluate the fit,
yhat=polyval(b,x(ix));
You can, of course, compare the two sets of coefficients from the above two cases and see just how much variation there is between the LS fit overall and the zero-slope case.
1 件のコメント
dpb
2016 年 10 月 26 日
Well, you commented "it didn't work for me" in unaccepting an answer which is rather pointless if you don't say what seems to be the problem you see.
It certainly does what you asked for; how well it represents the data was going to be marginal at best as we warned you going in...but, show the results and what you think isn't right...we don't have the data.
参考
カテゴリ
Help Center および File Exchange で Polynomials についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!