How can I get the input name of an expression?

3 ビュー (過去 30 日間)
aacarey
aacarey 2015 年 1 月 21 日
回答済み: Star Strider 2015 年 1 月 21 日
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
  1 件のコメント
dpb
dpb 2015 年 1 月 21 日
Sometimes we want what we can't have...

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

回答 (1 件)

Star Strider
Star Strider 2015 年 1 月 21 日
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.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by