       RE: structure array equivalent in Mathematica

• To: mathgroup at smc.vnet.net
• Subject: [mg67211] RE: [mg67162] structure array equivalent in Mathematica
• From: "David Park" <djmp at earthlink.net>
• Date: Sun, 11 Jun 2006 23:08:53 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Kevin,

Generally you would use Part. But if you wanted to make a more convenient
usage you could do something like the following. First create some sample
data.

data = Table[{p[i], t[i], wv[i]}, {i, 1, 5}];

observation[i_] := Part[data, i]
pressure := Part[#, 1] &
temperature := Part[#, 2] &
watervapor := Part[#, 3] &

pressure@observation
p

watervapor@observation
wv

temperature /@ data
{t, t, t, t, t}

David Park

From: kevin_jazz [mailto:kevinbowman at mac.com]
To: mathgroup at smc.vnet.net

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: ? about Rule (rewritten)
• Next by Date: Re: structure array equivalent in Mathematica
• Previous by thread: structure array equivalent in Mathematica
• Next by thread: Re: structure array equivalent in Mathematica