This example from the doc shows table is able to retrieve the variable names of the iput arguments list and uses them as column name:
LastName = {'Sanchez';'Johnson';'Li';'Diaz';'Brown'};
Age = [38;43;38;40;49];
Then
T = table(LastName,Age)
I get
T =
5×2 table
LastName Age
_________ ___
'Sanchez' 38
'Johnson' 43
'Li' 38
'Diaz' 40
'Brown' 49
For
T = table(LastName,Age+1)
I get
T =
5×2 table
LastName Var2
_________ ____
'Sanchez' 39
'Johnson' 44
'Li' 39
'Diaz' 41
'Brown'
My question is simple: how can do the same (retrieve the variable names) within my own function?
If yes, same question for output arguments:
bar = foo(123);
can foo retrieves 'bar'?

 채택된 답변

Stephen23
Stephen23 2018년 11월 6일

1 개 추천

댓글 수: 4

Bruno Luong
Bruno Luong 2018년 11월 6일
Thanks. It doesn't look like the dual outputname exists?
Stephen23
Stephen23 2018년 11월 6일
Correct, outputname does not exist.
Peter Perkins
Peter Perkins 2018년 11월 15일
inputname can be, and has been, way over-used. A little goes a long way. In particular, it is a really bad idea to get the names of your inputs and then overwrite them using evalin.
You may not have wanted to do that. But don't do that.
Bruno Luong
Bruno Luong 2018년 11월 15일
Never use it myself (thus the question), but I can see some circumstances I would want to use it:
  1. Put some more meaningful error message or log message
  2. Check if the input argument is from an expression of a variable, in the MEX file I might not bother to perform inplace change in the first case to save some memory or duplication.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2018년 11월 6일

댓글:

2018년 11월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by