How to add trendline to scatterplot?
    342 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
hi, I have 2 variables with data, like 
x=2 1 4 68  4 5
y=5 4 2 23 21 50
I want to add trendline to the scatter plot. how can I do that?
0 commentaires
Réponse acceptée
  Ameer Hamza
      
      
 le 27 Déc 2020
        Something like this
x = [2 1 4 68  4 5]
y = [5 4 2 23 21 50]
p = polyfit(x, y, 1);
px = [min(x) max(x)];
py = polyval(p, px);
scatter(x, y, 'filled')
hold on
plot(px, py, 'LineWidth', 2);
2 commentaires
Voir également
Catégories
				En savoir plus sur Annotations 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!