How do I name the trendline in the legend? Also, how can I get the trend line equation on the plot?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
0 commentaires
Réponses (2)
Bjorn Gustavsson
le 19 Mar 2019
Maybe:
if c(2) > 0
equation_string = sprintf('%4.3f x + %4.3f',c(1),c(2));
elseif c(2) < 0
equation_string = sprintf('%4.3f x - %4.3f',c(1),abs(c(2)));
else
equation_string = sprintf('%4.3f x',c(1));
end
legend('Data',['Best linear fit: ',equation_string])
text(12,43,equation_string)
HTH
0 commentaires
Star Strider
le 19 Mar 2019
It is not possible to run an image of your code.
Try this:
Voltage = linspace(10.45, -1.4, 8);
GaugePressure = linspace(3353, 0, 8);
c = polyfit(Voltage, GaugePressure, 1);
y_est = polyval(c, Voltage);
figure
plot(Voltage, GaugePressure, '--bs')
hold on
plot(Voltage, y_est, 'r--')
hold off
legend('Data', 'TrendLine', 'Location','best')
Add your title and axis label calls.
0 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!