Mathematica and large data arrays

  • Mathematica
  • Thread starter jd83605
  • Start date
  • #1
3
0

Main Question or Discussion Point

Hi,

I have imported a data set from EXCEL that is 18 columns wide and 25 rows long. Each row of data appears within it own set of brackets as expected. I am able to pull out individual elements of the array. However, I want to plot column 2 vs column 4. How might I extract those two columns of data from my imported data? Moreover, the first two rows are text that I would prefer to omit.

Data format:

{a11,a12,....a118}
{a21,a22,....a218}
.
.
.
{a251,a252,...a2518}

Any help would be appreciated. I cannot find a similar topic at the Wolfram site.

Jim
 

Answers and Replies

  • #2
313
1
The Part[...] command should probably be enough for this. It has the abbreviation [[...]].
Ranges in Part are specified using ;;, so e.g.
list[[4;;10;;2]]
will give you the elements at positions {4,6,8,10}.

Here's an array the same size as your data
data = Array[a, {18, 25}];

To extract the 2nd column you can write
data[[All,2]]
or
Transpose[data][[2]]

To extract the 2nd column with out the first element, use
data[[2;;,2]]
or
Transpose[data][[2,2;;]]

To extract the 2nd and 4th column without the first elements use
data[[2 ;;, {2, 4}]]

Then this can be plotted with ListPlot. Eg, here's some random data
data = Accumulate[RandomReal[{0, 1}, {18, 25}]];
which is plotted using
ListPlot[data[[2 ;;, {2, 4}]], Joined -> True, PlotMarkers -> Automatic]
 
  • #3
3
0
Thanks for the input. I was able to extract the data using a variation of what you gave me. However, I cannot make it plot. I simply get a default graph from -1 to 1 on both axes and no data.

Here is what I was able to do.
In[127]:= tmp =
Import["E:/filename.xlsx", "FormattedData"][[1, 3 ;;, {2, 4}]]

Out[127] = {{22.7,-2.95},{22.70,-2.983}...{22.7,-3.09}}

ListPlot[tmp] gives me an empty graph. I have tried playing with DataRange with no success.

as always thanks for any assistance.

Jim
 
  • #4
313
1
I'm not sure why you're getting an empty plot. But the small extract of the data you provided above has the x-values for all terms equal, so you'd be getting a vertical line...
(I removed the dots and plotted it to check - it works fine.)
Maybe use Joined->True option so that you can see the line...
 
  • #5
3
0
It turns out if I remove the "FormattedData" option from the import command ListPlot works fine. Apparently, that option doesn't put the numbers in the approrpiate format.

I truncated the data to make it easier to observe. That is why it appears as a vertical line.

Thanks for your input.
 
  • #6
313
1
Glad you got it sorted!
 

Related Threads on Mathematica and large data arrays

Replies
4
Views
7K
Replies
2
Views
2K
Replies
1
Views
3K
Replies
6
Views
12K
Replies
4
Views
3K
Replies
5
Views
5K
Replies
4
Views
3K
Replies
12
Views
24K
Replies
13
Views
5K
Replies
2
Views
2K
Top