Applying text with variable on a plot
13 ビュー (過去 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)
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!