Convert Variable Name to Text and Use in Plot Title
조회 수: 10 (최근 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.
댓글 수: 0
채택된 답변
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.]
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Title에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!