Applying text with variable on a plot
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi. I drew a trend line in the plot and want to apply text
"R^2= Rsq1", where Rsq1 is a value got from calculation.
The figure attached shows the plot and text from my code (undesirable repeat of R^2=).
How can I apply test of "R^2= 99.5" when Rsq1=99.5?
p1 = polyfit(E1(:,3),E1(:,1),1);
yfit1 = polyval(p1, E1(:,3));
X1=-0.05:0.05:0.55;
Y1=p1(1)*X1+p1(2);
SStot1 = sum((E1(:,1)-E1(:,3)).^2);
SSres1 = sum((E1(:,1)-yfit1).^2);
Rsq1 = 1-SSres1/SStot1;
hold on
plot(X1,Y1);
txt = 'R^2 =';
text(X1,Y1,txt)
0 commentaires
Réponse acceptée
Ive J
le 28 Oct 2021
I don't have your dataset but you can follow this example:
plot(3:10, (6:13).^2, 'k.-', 'LineWidth', 1.5)
Rsq = 0.64645;
h = gca;
pos = [h.XLim(1) + 0.1*diff(h.XLim), h.YLim(2) - 0.1*diff(h.YLim)]; % top left corner
text(pos(1), pos(2), compose("R^2 = %.2f", Rsq))
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Distribution Plots 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!