Problems with printing superscripts in a textbox in a graph
조회 수: 4 (최근 30일)
이전 댓글 표시
Dear colleagues,
I need to write regression results on graphs with several subplots. Texts are prepared in the same loop:
[c3,r2] = fit(data.P_mm_yr(aaa),data.ET_mm_yr(aaa),f);
subplot(Nrows,Ncols,i);
plot(c3,data.P_mm_yr(aaa),data.ET_mm_yr(aaa));
xlim([0 4000]); ylim([0 4000]);
paramstxt = cell(3,1);
paramstxt{1}=num2str(c3.a0,3);
paramstxt{2}=num2str(c3.a1,3);
paramstxt{3}=num2str(c3.c,3);
txtE = {strcat('y = ',paramstxt{1},'*x/(1+',paramstxt{2},'*x^{\',paramstxt{3},'}',')')...
;strcat('R^2 = ' ,num2str(r2.adjrsquare,2))};
text(800,3000,txtE);
legend('off');
However, in some cases text output is OK, e.g., this one:
'y =2.05e+04*x/(1+200*x^{\0.728})'
'R^2 =-0.11'
And in other cases I got the error message:
Warning: Error updating Text.
String scalar or character vector must have valid interpreter syntax:
y =0.925*x/(1+2.82e-07*x^{\2.15})
R^2 =0.33
What is a problem?
Another question: on the graph with regression results (points and regression line) I need also to add a strate line 1:1. How can I do it?
댓글 수: 0
채택된 답변
Cris LaPierre
2021년 4월 12일
편집: Cris LaPierre
2021년 4월 12일
Remove the backslash in your exponent.
c3.a0 = 0.925;
c3.a1 = 2.82e-7;
c3.c = 2.15;
r2.adjrsquare = -0.11;
paramstxt = cell(3,1);
paramstxt{1}=num2str(c3.a0,3);
paramstxt{2}=num2str(c3.a1,3);
paramstxt{3}=num2str(c3.c,3);
txtE = {strcat('y = ',paramstxt{1},'*x/(1+',paramstxt{2},'*x^{',paramstxt{3},'}',')')...
;strcat('R^2 = ' ,num2str(r2.adjrsquare,2))};
text(800,3000,txtE);
xlim([0 4000]); ylim([0 4000]);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!