MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: returning a variable's name, rather than the variable's contents


Michael Stern wrote:
> There must be a simple way to do this but it eludes me. Take for example the
> following: 
> 
> In[2]:= a=1;b=2;c=3;
> 
> In[3]:= Max[a,b,c]
> 
> Out[3]= 3
> 
> What would I do if I wanted Out[3] to equal "c" ?

What about the following trick?

In[1]:=
vars = {a, b, c};
varNames = ToString /@ vars;
values = {1, 2, 3};
vars = values;
First[Extract[varNames, Position[vars, Max[vars]]]]

Out[5]=
"c"

HTH,
Jean-Marc


  • Prev by Date: Re: returning a variable's name, rather than the variable's contents
  • Next by Date: Re: How to treat this false singular point?
  • Previous by thread: Re: returning a variable's name, rather than the variable's contents
  • Next by thread: RE: returning a variable's name, rather than the variable's contents