1
$\begingroup$

I'm very new to Mathematica. I'm just trying to plot some data, but Mathematica says there isn't a 7th element my data which is an array of 7 elements. The code before the plot is here:

x = Import["C:\\Useres\\PC\\Documents\\alt.csv","Table"];
a = x[[;;,7]];
tmp = x[[;;, 1;;6]];
dt = DateObject[tmp];

Mathematica also says it cannot take positions 1 through 6 in the first row of my data. I have to be doing something wrong, but I have no idea what.

I've searched as much as I could to find out what's wrong, but everything I find on Mathematica is super technical jargon I don't understand and irrelevant to my issue besides.

Any help would be appreciated.

Edit

x is a file with 16,382 rows and 7 columns. The first six columns are the date and time, and the last is altitude. The interval between rows is one second.

$\endgroup$
  • $\begingroup$ Where's your definition of x? $\endgroup$ – John Doty Oct 20 at 22:54
  • $\begingroup$ What is x? Please post a complete code that allows to fully reproduce your issue. For examples, it x is a string your code won't work. $\endgroup$ – corey979 Oct 20 at 22:55
  • 1
    $\begingroup$ Assuming x = {2018, 09, 27, 12, 13, 50, 153.2}, ;; is equivalent to All which is why x[[;;,7]] generates an error. Why not just x[[7]] or x[[1 ;; 6]]. If you had a list of lists then the form you are using would apply. e.g. {x, x}[[;; , 7]]. $\endgroup$ – Rohit Namjoshi Oct 20 at 22:56
  • 1
    $\begingroup$ What is the result of Dimensions[x]? $\endgroup$ – MassDefect Oct 21 at 0:55
  • $\begingroup$ Thanks @MassDefect, that lead me to my answer. The output showed only one column, not seven. $\endgroup$ – Oliver Oct 21 at 17:52
1
$\begingroup$

I used Dimensions[x] and found that Mathematica was only outputting one column.

Mathematica sees the csv data file as only having one column because "Table" is written in the import function when it should be "csv".
So this code:

x = Import["C:\\Useres\\PC\\Documents\\alt.csv","Table"];  

should instead be:

x = Import["C:\\Useres\\PC\\Documents\\alt.csv","csv"];
$\endgroup$
  • $\begingroup$ Actually, just Import["C:\\Useres\\PC\\Documents\\alt.csv","csv"] will work. $\endgroup$ – m_goldberg Oct 28 at 1:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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