Linear Regression - how to incorporate in figure

2 vues (au cours des 30 derniers jours)
Osnofa
Osnofa le 16 Juil 2019
Commenté : KSSV le 16 Juil 2019
Hello,
I have the following data:
x=[1 2 5 9 4 10 11 2 6]
y=[5 3 6 8 5 12 14 4 8]
I need to obtain a figure with:
  1. plot x y
  2. linear regression - y=mx+b
  3. Legend with linear regression equation y=mx+b
  4. R square value
But still have not managed to achieve points 3 and 4.
thanks

Réponses (1)

KSSV
KSSV le 16 Juil 2019
Read about plotregression
x=[1 2 5 9 4 10 11 2 6] ;
y=[5 3 6 8 5 12 14 4 8] ;
plotregression(x,y);
  2 commentaires
Osnofa
Osnofa le 16 Juil 2019
Is it possible to increase resolution of m and b values? m has 2 digits after decimal point while b only has 1 which is inconsistent and insuficient.
It works but it is not quite what I was looking for. I was looking for something as excel provides:
sample_figure.PNG
nevertheless, thank you.
KSSV
KSSV le 16 Juil 2019
p = polyfit(x,y,1)

Connectez-vous pour commenter.

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by