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?
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!