Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: Copy and Pasting Tables into Spreadsheet

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83500] Re: Copy and Pasting Tables into Spreadsheet
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Wed, 21 Nov 2007 03:07:16 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fhp2jd$1q6$1@smc.vnet.net> <fhu71j$70l$1@smc.vnet.net>

gregory.lypny at videotron.ca wrote:

<snip>

> Is there a way to tell
> Mathematica to return a scalar in all situations when the result would
> otherwise be a list with only one element?

Gregory,

You could use the system variable *$Post* and set up your own post 
processing function. (You might be interested in $PrePrint too.) Here is 
an example of such a function that should do what you are looking for, 
though you may want to add some additional tests (or remove few of them).

In[1]:= $Post =
   If[Head[#] === List && Length[#] == 1 &&
      Depth[#] < 3, #[[1]], #] &;

prob = {.4, {.6}, {.4, .6}, {{.4, .6}}};

prob[[1]] (* Scalar: not a list, depth one *)
prob[[2]] (* List of length one and depth two *)
prob[[3]] (* List of length two and depth two *)
prob[[4]] (* List of length one and depth three *)

$Post =. (* Reset $Post *)

Out[3]= 0.4

Out[4]= 0.6

Out[5]= {0.4, 0.6}

Out[6]= {{0.4, 0.6}}

Best regards,
-- 
Jean-Marc


  • Prev by Date: Re: Copy and Pasting Tables into Spreadsheet
  • Next by Date: DataRange
  • Previous by thread: Re: Copy and Pasting Tables into Spreadsheet
  • Next by thread: Re: Re: Copy and Pasting Tables into Spreadsheet