Azzera filtri
Azzera filtri

How to get the regression from 2 vectors

17 visualizzazioni (ultimi 30 giorni)
Shani
Shani il 22 Nov 2013
Modificato: Image Analyst il 23 Nov 2013
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 Commento
Image Analyst
Image Analyst il 23 Nov 2013
Modificato: Image Analyst il 23 Nov 2013
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

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 22 Nov 2013
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 Commento
Image Analyst
Image Analyst il 22 Nov 2013
Modificato: Image Analyst il 22 Nov 2013
My x and y are vectors. What do you have? Give code to generate the kind of data you have.

Accedi per commentare.

Categorie

Scopri di più su Linear and Nonlinear Regression in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by