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"];
channels = {"RF", "MH", "LH", "VL", "AT", "MH"};
    Print @ 
      ListLinePlot[data {{j, i}}, 
        AspectRatio -> 0.2, 
        PlotRange -> All, 
        PlotLabel -> channels[[i]], 
        MaxPlotPoints -> 10000],
    {j, 2, All],
  {i, 1, 5}];
  • $\begingroup$ Thank you for editing @m_goldberg $\endgroup$
    – JamesP
    Commented Apr 26, 2015 at 1:05
  • $\begingroup$ Your .mat file does not seem to exist. $\endgroup$ Commented Apr 26, 2015 at 2:35

1 Answer 1


See if this helps you get started

data = First[Import["x21432.mat"]] /. {{x_Real}}->x;
channels = {"RF", "MH", "LH", "VL", "AT", "MH"};
 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.

  • $\begingroup$ 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. $\endgroup$
    – JamesP
    Commented Apr 26, 2015 at 2:48
  • $\begingroup$ @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. $\endgroup$
    – Bill
    Commented Apr 26, 2015 at 2:53
  • $\begingroup$ 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. $\endgroup$
    – JamesP
    Commented Apr 26, 2015 at 3:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.