Problems with printing superscripts in a textbox in a graph
4 views (last 30 days)
Show older comments
Fyodor Tatarinov
on 12 Apr 2021
Commented: Fyodor Tatarinov
on 14 Apr 2021
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 Comments
Accepted Answer
Cris LaPierre
on 12 Apr 2021
Edited: Cris LaPierre
on 12 Apr 2021
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]);
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!