How to write an exponent in an axis label when the matlab syntax doesn't work?

The matlab syntax for writing an exponent in an axis label is
ylabel('e^t')
but when I try to do this on my figure I get the following error:
>> ylabel('e^t')
Warning: Error updating Text.
String scalar or character vector must have valid interpreter syntax:
e^t
Instead of getting an exponent, my axis label shows 'e^t' How do I resolve this issue?

8 comentarios

Seems to be working here for this particular case.
Could you please share your code and mention which version of MATLAB you have?
fplot(@exp)
ylabel('e^t')
This is my code and I am using MATLAB 2023b.
t = -5:.01:5;
x = exp(t/10);
figure(1)
scatter(x,t,24,'filled')
xlabel('t')
ylabel('e^(t/10)')
Try this -
t = -5:.01:5;
x = exp(t/10);
figure(1)
scatter(x,t,24,'filled')
xlabel('t')
ylabel('e^{(t/10)}')
It still gives the error with or without using the curly braces
Brianna Miranda
Brianna Miranda el 22 de En. de 2024
Movida: Dyuman Joshi el 25 de Feb. de 2024
I still get the same warning and on my plot it includes the curly braces in the text.
String scalar or character vector must have valid interpreter syntax:
e^{(t/10)}
ylabel('e^t')
What MATLAB version are you using?
Please show the exact code that you are calling.
Please show the complete output of this command:
which ylabel -all
Do you receive that error running just that one line of code? Or can you only reproduce it with more lines (hopefully just a few lines)? Please post a small and self-contained example that you can run (in a fresh session of MATLAB, newly started) that produces the warning.
xlabel('e^{(t/10)}')
The one thing I'm thinking of that might cause this with just that line of code is if you've change the default Interpreter property for text objects first.
f = figure;
set(f, 'DefaultTextInterpreter', 'LaTeX')
xlabel('e^{(t/10)}')
Warning: Error updating Text.

String scalar or character vector must have valid interpreter syntax:
e^{(t/10)}
In that case try wrapping that label text in $.
f = figure;
set(f, 'DefaultTextInterpreter', 'LaTeX')
xlabel('$e^{(t/10)}$')

Iniciar sesión para comentar.

Respuestas (1)

Brianna Miranda
Brianna Miranda el 22 de En. de 2024
Movida: Dyuman Joshi el 25 de Feb. de 2024
I decided to just uninstall and reinstall matlab and that fixed the problem

Categorías

Más información sobre MATLAB Coder en Centro de ayuda y File Exchange.

Productos

Versión

R2023b

Preguntada:

el 22 de En. de 2024

Movida:

el 25 de Feb. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by