Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a file that has 7 column but i only want to import two column from it, that is 1st and 3rd column from the file. How can i do that and this is the list for example:

{1.1033,6.1371,46471,0,1,,0}
{1.1064,6.2101,46504,0,1,,0}
{1.1371,0,46537,0,1,Z,0}
{1.1598,0.0731,46571,0,1,,0}
{1.1946,0.1461,46604,0,1,,0}
{1.1871,0.2192,46638,0,1,,0}
{1.217,0.2922,46671,0,1,,0}
{1.234,0.3653,46704,0,1,,0}
{1.2541,0.4384,46738,0,1,,0}
{1.2509,0.5114,46771,0,1,,0}
{1.2244,0.5845,46805,0,1,,0}
{1.2009,0.6575,46838,0,1,,0}
{1.1916,0.7306,46871,0,1,,0}
{1.2287,0.8037,46905,0,1,,0}
{1.2406,0.8767,46938,0,1,,0}
{1.2517,0.9498,46971,0,1,,0}
{1.2385,1.0228,47005,0,1,,0}
{1.2545,1.0959,47038,0,1,,0}
share|improve this question

closed as off-topic by bobthechemist, RunnyKine, rasher, Öskå, Michael E2 Jun 24 at 0:04

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – bobthechemist, RunnyKine, rasher, Öskå
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Do you want to Import just two columns from a file instead of the whole file or do you want to import the whole file and extract only two columns? Regardless, both questions already have answers on this site. –  RunnyKine Jun 23 at 22:14
    
possible duplicate of Plot data from txt file? –  Michael E2 Jun 24 at 0:04
    
I voted to close as a duplicate because I think answer is in the linked question in my comment above. @Irah, you should look there. –  Michael E2 Jun 24 at 0:08

2 Answers 2

data =
 {{1.1033, 6.1371, 46471, 0, 1, , 0},
   {1.1064, 6.2101, 46504, 0, 1, , 0},
   {1.1371, 0, 46537, 0, 1, Z, 0},
   {1.1598, 0.0731, 46571, 0, 1, , 0},
   {1.1946, 0.1461, 46604, 0, 1, , 0},
   {1.1871, 0.2192, 46638, 0, 1, , 0},
   {1.217, 0.2922, 46671, 0, 1, , 0},
   {1.234, 0.3653, 46704, 0, 1, , 0},
   {1.2541, 0.4384, 46738, 0, 1, , 0},
   {1.2509, 0.5114, 46771, 0, 1, , 0},
   {1.2244, 0.5845, 46805, 0, 1, , 0},
   {1.2009, 0.6575, 46838, 0, 1, , 0},
   {1.1916, 0.7306, 46871, 0, 1, , 0},
   {1.2287, 0.8037, 46905, 0, 1, , 0},
   {1.2406, 0.8767, 46938, 0, 1, , 0},
   {1.2517, 0.9498, 46971, 0, 1, , 0},
   {1.2385, 1.0228, 47005, 0, 1, , 0},
   {1.2545, 1.0959, 47038, 0, 1, , 0}};

Get 1st and 5th column:

{#[[1]], #[[5]]} & /@ data
share|improve this answer
    
This can also be written data[[All, {1, 5}]] –  Bob Hanlon Jun 23 at 22:05
    
@BobHanlon - Thanks (I didn't know that). Part seems to offer endless possibilities ... –  eldo Jun 23 at 22:13

The documentation for Part shows you how to extract a column from an array:

{{a, b, c}, {d, e, f}, {g, h, i}}[[All, 2]]
{b, e, h}

so in your case, assuming the data was imported as a nested array such as from a CSV file, would be

data[[All,{1,3}]]
share|improve this answer

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