       Re: structure array equivalent in Mathematica

• To: mathgroup at smc.vnet.net
• Subject: [mg67201] Re: structure array equivalent in Mathematica
• From: bghiggins at ucdavis.edu
• Date: Sun, 11 Jun 2006 23:08:16 -0400 (EDT)
• References: <e6gdun\$ngj\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```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

In:=pressure/.Observation

Out=34.6

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

In:=pressure/.MoreObservations[]

Out=38.6

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

Cheers,

Brian

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.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