Re: How to navigate the documentation?
- To: mathgroup at smc.vnet.net
- Subject: [mg110153] Re: How to navigate the documentation?
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Fri, 4 Jun 2010 08:02:51 -0400 (EDT)
On 6/3/10 at 5:39 AM, no.email at please.post (kj) wrote: >This question is about the Mathematica documentation, but it would >more helpful to pose it in terms of an example question: >"I have a file containing newline-separated records. The fields in >each record are separated by tabs. The number of fields varies from >one record to the next, but it always has the form 2*(n+1), where n >>= 3. The first two fields are always alphabetic strings; the >remaining 2*n fields are real numbers (expressed using the "E" >notation: e.g. 1.23E-4 == 0.000123), and they represent n points in >R^2. In summary records have the following form: ><string> <TAB> <string> <TAB> <real> <TAB> ... <TAB> <real> <NL> >I want to read this file into a Mathematica structure having the >form >{String, String, {{Real, Real}, {Real, Real}, {Real, Real}, ...}} " >OK, now: The *challenge* is to find the answer to the question above >in the Mathematica documentation. I don't think there is a pre-defined method to to this and consequently would not expect to be able to find this in the documentation. But it is simple to get the desired format using Import and a replacement rule. Specifically, Import[filename, "TSV"] /. {a_String, b_String, c__} :> {a, b, Partition[{c}, 2]} will produce the desired result >OK, here's a much simpler question: >"In Mathematica, how do I convert the string "1.23E-4" the real >number 0.000123?" >The *challenge* now is like before: find the answer to this (much >simpler) question in the Mathematica documentation. This can be accomplished with a single function as follows: In[44]:= ImportString["1.23E-4", "Table"][[1, 1]] Out[44]= 0.000123 I've not got really good answers as to navigating the documentation. To a large extent, this will depend on your familiarity with Mathematica. A possible sequence which would lead to a partial answer to your first question would be to search on File in the DocumentationCenter. The first entry in the result is FieFormat. Clicking on that brings up a brief description indicating its usage with Import. And clicking on Import in this description brings up the documentation for Import. This should be sufficient to determine Import[filename, "TSV"] or Import[filename,"Table"] would do the basic job of reading the file. But then knowing about replacement rules to change the result into the desired form isn't something easily solve by simply searching documentation without having a reasonable understanding of Mathematica. And note, the second item in the results returned by searching on File in the documentation center is StringFormat which leads to ImportString in the same manner as FileFormat leads to Import.