Problems with printing superscripts in a textbox in a graph

3 次查看(过去 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?

采纳的回答

Cris LaPierre
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]);
Also, for straight lines, look into xline and yline.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by