Writing an exponential equation in the title
조회 수: 28 (최근 30일)
이전 댓글 표시
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
답변 (3개)
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
댓글 수: 0
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
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
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!