Trying to get symbols to display a formula in title of uiaxes bar plot

조회 수: 1 (최근 30일)
I am trying to get symbols to display a formula in title of uiaxes bar plot. In the beginning it was like this. I enter this code :
app.UIAxes_4.Title.String = 'Sigma of each cell, $$\sigma = \sqrt{1/N*\Sigma_N(E-R_{ref})^2}$$'
and then I got this.
This is correct. But I want to add this along with it
This is from another normal plot and i generated this by using the code :
titl1 ='best \sigma = ';
titl2 = num2str(app.bestSigma);
titl3 = ' worst \sigma= ';
titl4 = num2str(app.worstSigma);
titl = strcat(titl1,titl2,titl3,titl4);
app.UIAxes_3.Title.String = titl;
And now I try to combine this :
titl1 ='Sigma of each cell, $$\sigma = \sqrt{1/N*\Sigma_N(E-R_{ref})^2}$$, best \sigma = ';
titl2 = num2str(app.bestSigma);
titl3 = ' worst \sigma= ';
titl4 = num2str(app.worstSigma);
titl = strcat(titl1,titl2,titl3,titl4);
app.UIAxes_4.Title.String = titl;
But I end up getting this :
I even tried this :
app.UIAxes_4.Title.String = "Sigma of each cell, $$\sigma = \sqrt{1/N*\Sigma_N(E-R_{ref})^2}$$, best \sigma = " + num2str(app.bestSigma) + " worst \sigma= " + num2str(app.worstSigma);
and still ended up getting the same wrong answer.
So how can I combine the first two images to get the solutioin for a title in an UIaxes bar plot. Thank you.
  댓글 수: 1
Epsilon
Epsilon 2025년 6월 26일
편집: Epsilon 2025년 6월 26일
Try:
titl = sprintf(['Sigma of each cell, $$\\sigma = \\sqrt{\\frac{1}{N}\\sum_N(E-R_{ref})^2}$$, ', ...
'best $\\sigma = %.3f$, worst $\\sigma = %.3f$'], ...
app.bestSigma, app.worstSigma);
app.UIAxes_4.Title.String = titl;
app.UIAxes_4.Title.Interpreter = 'latex';

댓글을 달려면 로그인하십시오.

답변 (1개)

Govind Sankar Madhavan Pillai Ramachandran Nair
Thank you very much. It worked, but there is a new issue. This issue was there before as well, that as you can see in the title sigma of each cell and the formula are in two different lines. I ignored it at that, but when we add the new stuff to it, the whole title is in 3 lines which makes the plot too small and totally doesnt look good.
I tried changing the title from char array to a string, but didnt help, it went to the old issue, of not showing the formula. Is it possible to put it in one line or its either 3 lines or nothing.

카테고리

Help CenterFile Exchange에서 Title에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by