Convert Variable Name to Text and Use in Plot Title

조회 수: 10 (최근 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 CenterFile Exchange에서 Title에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by