Convert Variable Name to Text and Use in Plot Title

12 ビュー (過去 30 日間)
Jon
Jon 2025 年 4 月 29 日
コメント済み: Jon 2025 年 4 月 30 日
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.

採用された回答

Steven Lord
Steven Lord 2025 年 4 月 29 日
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 件のコメント
Jon
Jon 2025 年 4 月 30 日
Thanks for your response.
Good to read that article about avoiding doing the dynamic naming.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTitle についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by