How can I get the input name of an expression?
3 ビュー (過去 30 日間)
古いコメントを表示
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 件)
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!