Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68461] Re: returning a variable's name, rather than the variable's contents
  • From: Peter Pein <petsie at dordos.net>
  • Date: Sun, 6 Aug 2006 02:56:32 -0400 (EDT)
  • References: <eauvns$17c$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Michael Stern schrieb:
> 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" ?
> 
>  
> 
> Thanks in advance,
> 
>  
> 
> Michael Stern
> 
> 
> 

Hi Michael,

  I'm not familiar with the string functions in Mathematica. Therefore a much simpler approach will exist; but this one works:

In[1]:=
Attributes[nameOfMax] := {HoldAll};
nameOfMax[l__] :=
   Module[{ls = StringJoin[", ", StringDrop[StringDrop[ToString[Unevaluated[l]], 9], -1], ","], sp},
     sp = First /@ StringPosition[ls, ","];
     StringTake[ls, sp[[{#1, #1 + 1}]] + {2, -1}]& [Last[Ordering[{l}]]]]
In[3]:=
{a, b, c, huge} = {1, 2, 3, 10^10};
In[4]:=
nameOfMax[a, b, c]
Out[4]=
"c"
In[5]:=
nameOfMax[c, huge, a, b]
Out[5]=
"huge"

HTH,
   Peter


  • Prev by Date: Eigensystem[] for higher dimensions?
  • Next by Date: Re: How to do Chebyshev expansion in Mathematica?
  • Previous by thread: RE: returning a variable's name, rather than the variable's contents
  • Next by thread: Re: Re: returning a variable's name, rather than the variable's contents