Writing an exponential equation in the title

조회 수: 28 (최근 30일)
Akhil Vasvani
Akhil Vasvani 2017년 3월 6일
이동: Sam Chak 2024년 10월 2일
I would like to write my exponential equation in the title of my figure. Right now I have:
title(['y = ',num2str(a),' x^', (num2str(n))]);
The problem is my equation comes out as: y = 8.56 x^(0).68, which is not what I want.
I want would the title to be y = 8.56 x^(0.68). How do I do this?
  댓글 수: 1
Abdoulaye
Abdoulaye 2024년 10월 2일
이동: Sam Chak 2024년 10월 2일
str=num2str(n);
temp=[1:length(str) 0.5:(length(str)-0.5)];
str=[str repmat('^',1,length(str))];
[~,temp]=sort(temp);
str=str(temp);
if true title(['y = ',num2str(a),' x', str]); end

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

답변 (3개)

John BG
John BG 2017년 3월 7일
편집: John BG 2017년 3월 7일
Akhil
you mean this
a=8.56;n=0.68; figure; title(['y = ' num2str(a) ' x^{' num2str(n) '}' ]);
.
if you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG

Walter Roberson
Walter Roberson 2017년 3월 6일
title( sprintf('y = %.2f x^{%.2f}', a, n) );

Rik
Rik 2017년 3월 6일
This syntax is essentially calling TeX, so it follows that syntax. It doesn't, however support accolades for grouping commands, so you'll have to repeat the ^ sign.
I suspect there is faster, more stable and more elegant way to do it, but this should work:
str=num2str(n);
temp=[1:length(str) 0.5:(length(str)-0.5)];
str=[str repmat('^',1,length(str))];
[~,temp]=sort(temp);
str=str(temp);
if true title(['y = ',num2str(a),' x', str]); end
  댓글 수: 2
Walter Roberson
Walter Roberson 2017년 3월 7일
I do not think I have ever seen "accolades" used in that context??
TeX uses {} to group; the approach I posted in my Answer works fine.
Rik
Rik 2017년 3월 8일
'Accolade' is the Dutch word for the curly bracket, so that's why I used that word (thinking the English word would also cover this meaning).
Some time ago I have tried to get subscript and superscript in my xlabel and ylabel, but there the {} didn't seem to work, so I assumed that it would work in the title either.

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by