# Using list of rules from imported .mat file

I'm attempting to learn Mathematica to replace MATLAB. However, I have some data in .mat files which contains named variables. Whenever I import the .mat file, I get a list of rules. What's the best way to go about using these? Let's say I wanted to plot some of the LabeledData, say "n2_den". Would I do something like ListLinePlot[data]/.n2_den? Or would I be better off just converting the list of rules to a list like one of the recommendations shows when I import?

• Turn it into an Association. That's the equivalent to the structure arrays (struct) in Matlab. Btw., see here for more hints on how to transplate between Matlab and Mathematica. – Henrik Schumacher Jan 14 '19 at 22:33
• I really like this suggestion Henrick! I makes a lot of sense in how to now use the data I've imported. – Bo Johnson Jan 16 '19 at 18:55
• I am glad that this helped you. Welcome on Mathematica.StackExchange and have fun with Mahematica! – Henrik Schumacher Jan 16 '19 at 21:15

For your case (in a verbose style to clarify structure):

mydata = {earth_alts -> {{3}, {4}, {5}}};

myEarthAltsData = mydata[[1, 2]]


Here, mydata[[1,2]] takes the second part of the (first) association, i.e., gives just the list of values.

• That works great, thanks! Just as a follow-up then, what does it mean doing mydata[[1,2]] in terms of rules? I get the indexing in thinking about multidimensional lists, but not rules necessarily. – Bo Johnson Jan 15 '19 at 0:07
• @Bo, the this axiom of Mathematica is: "Everything is an expression.". And expressions are basically trees into which you can index with Part ([[...]]). In case of mydata[[1,2]] have a look at the internal representations by executing TreeForm[mydata] and TreeForm[mydata[[1, 2]]]. Do you see the pattern? – Henrik Schumacher Jan 16 '19 at 21:20
• That's a really neat way to visualize what's happening here, thanks for pointing it out @HenrikSchumacher! – Bo Johnson Jan 16 '19 at 22:42

Turn it into an Association. That's the equivalent to the structure arrays (struct) in Matlab.

Btw., see here for more hints on how to translate between Matlab and Mathematica.