How can I get the input name of an expression?

2 views (last 30 days)
aacarey
aacarey on 21 Jan 2015
Answered: Star Strider on 21 Jan 2015
I want to write a plotting function that takes in X and varargin, and displays the input name in the legend whether the input is an expression or a variable. In order to do this, I need to be able to grab the input names.
Possible inputs: myplot(csc.tvec,Zscore,csc.Score,sin(csc.tvec))
and the legend would read:
- Zscore
- csc.Score
- sin(csc.tvec)
I do not want to pass in additional arguments containing the names, nor do I want to add a csc.name field.
The function inputname does not work with expressions.
Thank you!
Here is a similar question, but the answer is not compatible with my goals for the function: http://www.mathworks.com/matlabcentral/newsreader/view_thread/305458

Answers (1)

Star Strider
Star Strider on 21 Jan 2015
I tend to agree with dpb. My only suggestion is that you experiment with using an anonymous function that then calls your plotting function. The anonymous function will pick up variables from the workspace if you provide them by the same name as in the function. You can then pass them by name as formal arguments to your plotting function (that your anonymous function would call) without having to pass them as specific parameters to your anonymous function. I haven’t experimented with this myself, but it should work.

Community Treasure Hunt

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

Start Hunting!