How to get the regression from 2 vectors

9 ビュー (過去 30 日間)
Shani
Shani 2013 年 11 月 22 日
編集済み: Image Analyst 2013 年 11 月 23 日
Hi, I have 2 vectors and I would like to know the R^2 ie the regression of the line. I would like a line of best fit to show on the plot and the two vectors one on y and one on x axis thanks
  1 件のコメント
Image Analyst
Image Analyst 2013 年 11 月 23 日
編集済み: Image Analyst 2013 年 11 月 23 日
Here is what Shani asked, so that it will still be here when she deletes this question:
subject line: How to get the regression from 2 vectors
Hi, I have 2 vectors and I would like to know the R^2 ie the regression of the line. I would like a line of best fit to show on the plot and the two vectors one on y and one on x axis thanks

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2013 年 11 月 22 日
Try this demo:
% Create sample data and plot it.
x = 1:10;
y = 3*x - 20 + 4*rand(1, length(x)); % Some equation
plot(x, y, 'r*', 'MarkerSize', 15);
grid on;
% Get the fit
coeffs = polyfit(x, y, 1);
% Get the x values for the fit at higher resolution.
xFit = linspace(x(1), x(end), 300);
% Get the estimated y values
yFit = polyval(coeffs, xFit);
% Plot them as a line.
hold on;
plot(xFit, yFit, 'b-', 'LineWidth', 3);
  1 件のコメント
Image Analyst
Image Analyst 2013 年 11 月 22 日
編集済み: Image Analyst 2013 年 11 月 22 日
My x and y are vectors. What do you have? Give code to generate the kind of data you have.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by