# How to import data from a .mat or a .txt file and manipulate dimensions

I'm new to Mathematica (I know very, very little - so I apologize if anything I say is absolutely wrong) - but I'm trying to upload a file from matlab and arrange it in matrix form. I have a .mat file, (a 1082x5 cell), which I can also convert to a text file. When I import them into mathematica, I can't figure out how to get them in the exact form I had them in matlab.

Is there a way to change my matlab code to make this import easier, or possibly something in mathematica that would help? I've attached the .txt and .mat files, and here is the code I'm trying to run (I want 5 plots in the end - one for each column). Sorry if this is messy, first post - let me know how to improve questions. Thanks!

.mat file of the data http://www.filedropper.com/x21432
.txt file of the data http://www.filedropper.com/x21432_1

Here is the code Im trying to run:

data = Import["x21432.mat"];
Dimensions[data]
channels = {"RF", "MH", "LH", "VL", "AT", "MH"};
Do[
Do[
Print @
ListLinePlot[data {{j, i}},
AspectRatio -> 0.2,
PlotRange -> All,
PlotLabel -> channels[[i]],
MaxPlotPoints -> 10000],
{j, 2, All],
{i, 1, 5}];

• Thank you for editing @m_goldberg Commented Apr 26, 2015 at 1:05
• Your .mat file does not seem to exist. Commented Apr 26, 2015 at 2:35

See if this helps you get started

data = First[Import["x21432.mat"]] /. {{x_Real}}->x;
Dimensions[data]
channels = {"RF", "MH", "LH", "VL", "AT", "MH"};
Table[
ListLinePlot[Rest[data [[All, column]]], AspectRatio->0.2,
PlotRange->All, PlotLabel->channels[[column]]], {column, 1, Length[data[[1]]]}
]


The First in the first line gets rid of an extra layer of {} in your data. The {{x_Real}}->x gets rid of extra {{}} around each of your numbers. The Rest in the ListLinePlot gets rid of the RF as the first item in the first row of your data not being a number by tossing the whole first row. The Table replaces all your nested loops and fixes several errors at once.

• Thanks so much for the code and explanation! It did exactly what I was hoping, and fixed my later errors due to the nested loops. Commented Apr 26, 2015 at 2:48
• @JamesP Thanks. Check and make absolutely sure that I have not messed up your PlotLabel indexing. I may have an off-by-one, but I'm just guessing. Perhaps you could fix that by changing your channels list. Check it all very carefully before you trust it, as with any and all Mathematica code.
– Bill
Commented Apr 26, 2015 at 2:53
• I have a bunch of files to put through this code eventually, so I'll check in the future, but for now, It's all working properly! really appreciate the help. Commented Apr 26, 2015 at 3:01