フィルターのクリア

How to fit curve using regress

2 ビュー (過去 30 日間)
lucky_
lucky_ 2016 年 1 月 22 日
回答済み: Star Strider 2016 年 1 月 22 日
I'm not sure how regress work we were asked to generate regress function using
this >> Xliner = [X; ones(1,sampleData);];
but I don't know what does X represent in
sampleData = 100;
x = linspace(-5,5);
y= 1.6 * x .^2 + 2.5*x+6;
dataset = randn(2,sampleData);
figure
p = polyfit(x,dataset(1,:)+y,1);
r = p(1) .* x + p(2);
plot(x,dataset(1,:)+y,'ob','MarkerFaceColor','b')
hold on
plot(x,dataset(1,:)+y)
hold off
legend('raw data')
xlim([-4 6])

採用された回答

Star Strider
Star Strider 2016 年 1 月 22 日
You would use ‘Xliner’ if you need to do the linear regression using the mldivide function, or ‘\’ operator:
sampleData = 100;
x = linspace(-5,5);
y= 1.6 * x .^2 + 2.5*x+6;
dataset = randn(2,sampleData);
Xliner = [x; ones(1,sampleData)]';
p = Xliner\[dataset(1,:)+y]';
Notice the transpose (') operator.
It seems you were given incomplete information. See the documentation for mldivide for the details on how it works and how to use it.

その他の回答 (0 件)

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by