MathGroup Archive 2006

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

Search the Archive

Re: structure array equivalent in Mathematica

  • To: mathgroup at
  • Subject: [mg67201] Re: structure array equivalent in Mathematica
  • From: bghiggins at
  • Date: Sun, 11 Jun 2006 23:08:16 -0400 (EDT)
  • References: <e6gdun$ngj$>
  • Sender: owner-wri-mathgroup at

Kevin, One way is to enter the data as a set of rules:

Observation = {pressure -> 34.6, temperature -> 65, watervapor -> 12.0}

And then use the ReplaceAll (/.) operator to get at the specific data



With agregate data you could use

MoreObservations = {{pressure -> 34.6,
   temperature -> 65, watervapor -> 12.0}, {pressure -> 38.6,
temperature ->
      61, watervapor -> 10.5}}

Then the pressure on day 2 is then



One can dream up other ways in Mathematica to do what you want....



kevin_jazz wrote:
> Like many people I imagine, I'm transitioning to Mathematica from a
> background in another system.
> One of the common data types is the structure array.  Let's say I have
> an observational data set that includes pressure, temperature, and
> water vapor as a function of altitude.  So, in pseudo-code I might
> define a structure as
> observation = {pressure: float(100), temperature: float(100),
> water_vapor: float(100)}
> I could then access the elements of this observation as
> observation.pressure
> observation.temperature, etc.
> Furthermore, I could aggregate these observations into a larger list, e.g.
> obs_day = {observation, observation, observation}
> to be accessed as
> obs_day[1].pressure for the first element (assuming 1-index).
> Now, the list in Mathematica is quite powerful and I think can be
> set-up in a similar fashion.
> So my question is how is the structure array commonly implemented in
> Mathematica or its equivalent?
> If there is a previous thread (I looked but didn't find any) on the
> topic or in the Mathematica book or Mathematica Journal that I missed,
> feel free to point me in that direction.
> Many thanks,
> Kevin Bowman
> Jet Propulsion Laboratory

  • Prev by Date: RE: structure array equivalent in Mathematica
  • Next by Date: Re: ? about Rule (rewritten)
  • Previous by thread: RE: structure array equivalent in Mathematica
  • Next by thread: Re: structure array equivalent in Mathematica