Convert Variable Name to Text and Use in Plot Title
11 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Steven Lord
on 29 Apr 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.]
More Answers (0)
See Also
Categories
Find more on Title in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!