Effacer les filtres
Effacer les filtres

How to get the regression from 2 vectors

21 vues (au cours des 30 derniers jours)
Shani
Shani le 22 Nov 2013
Modifié(e) : Image Analyst le 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 commentaire
Image Analyst
Image Analyst le 23 Nov 2013
Modifié(e) : Image Analyst le 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

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 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 commentaire
Image Analyst
Image Analyst le 22 Nov 2013
Modifié(e) : Image Analyst le 22 Nov 2013
My x and y are vectors. What do you have? Give code to generate the kind of data you have.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Linear and Nonlinear Regression dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by