Writing an exponential equation in the title
17 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Risposte (3)
John BG
il 7 Mar 2017
Modificato: John BG
il 7 Mar 2017
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 Commenti
Rik
il 6 Mar 2017
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 Commenti
Walter Roberson
il 7 Mar 2017
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
il 8 Mar 2017
'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.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!