필터 지우기
필터 지우기

How can I get the input name of an expression?

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

Community Treasure Hunt

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

Start Hunting!

Translated by