Applying text with variable on a plot

11 次查看(过去 30 天)
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)

采纳的回答

Ive J
Ive J 2021-10-28
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 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by