Writing an exponential equation in the title

28 visualizaciones (últimos 30 días)
Akhil Vasvani
Akhil Vasvani el 6 de Mzo. de 2017
Movida: Sam Chak el 2 de Oct. de 2024
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 comentario
Abdoulaye
Abdoulaye el 2 de Oct. de 2024
Movida: Sam Chak el 2 de Oct. de 2024
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

Iniciar sesión para comentar.

Respuestas (3)

John BG
John BG el 7 de Mzo. de 2017
Editada: John BG el 7 de Mzo. de 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

Walter Roberson
Walter Roberson el 6 de Mzo. de 2017
title( sprintf('y = %.2f x^{%.2f}', a, n) );

Rik
Rik el 6 de Mzo. de 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 comentarios
Walter Roberson
Walter Roberson el 7 de Mzo. de 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
Rik el 8 de Mzo. de 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.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by