Convert Variable Name to Text and Use in Plot Title

11 visualizaciones (últimos 30 días)
Jon
Jon el 29 de Abr. de 2025
Comentada: Jon el 30 de Abr. de 2025
Hello,
I'd like to have the text of a variable be its own string, then use this in a title for a plot.
For example, I have a table called My_Table.
My_Table is a n x m table with actual data.
I'd like to take the words "My_Table" and use this as text so I can input it in my plot's title.
Is this possible?
What I tried/did was save a new variable like:
Plot_Title = My_Table;
But it grabs all the data within the table, if that makes sense.
Let me know if you'd like more information.
Thanks.

Respuesta aceptada

Steven Lord
Steven Lord el 29 de Abr. de 2025
In this simple case, just writing:
Plot_Title = 'My_Table'; % or
Plot_Title = "My_Table";
would do the trick.
If you want the name of the variable to be different based on different variables that you're plotting, how/where is that variable created before you use it for plotting? Did you create it in a script, did you load it from a MAT-file, did you create it and pass it into a function you've plotted, etc.? Knowing where that variable came from and how you refer to it in your plotting call may help suggest the right approach to include it in your plot title.
[If you created it dynamically using eval, the general consensus is to avoid doing that. That Discussions post explains why this is generally discouraged and offers several alternative approaches.]
  1 comentario
Jon
Jon el 30 de Abr. de 2025
Thanks for your response.
Good to read that article about avoiding doing the dynamic naming.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Title en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by