Applying text with variable on a plot
조회 수: 12 (최근 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!