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 .dat file from FORTRAN output and I am trying to plot the results. The dat file is a series of rows with the row number as the first column. Now, every other row is empty, that may be problematic. I am trying to plot the second column vs the third column (not the row nr that is, but the actual data). I can´t get the second and third column into an individual array. This is what I am trying to do

data = Import["C:\\Users....file.dat","Table"]
Grid[data]
1 1 0

2 0.999398 -0.000086244

3 0.997592 -0.000344186

4 0.994588 -0.000772091

Every other row in the table is empty, that is:

{}, {1, 1., 0.}, {}, {2, 0.999398, -0.000086244}, {},

I am trying to do

x = data[[ALL, 2]]

But I receive an error informing me that ALL is not an integer

Part::pspec: Part specification ALL is neither an integer nor a list of integers

How can I take all the values in the column 2 and 3 and store them in an individual arrays. If the empty rows will be problematic, how can I get rid of them?

share|improve this question
4  
Have a look at "IgnoreEmptyLines" here reference.wolfram.com/mathematica/ref/format/Table.html –  Ajasja Feb 8 '13 at 19:26
    
All right, thanks guys, I got it. –  l3win Feb 8 '13 at 19:38
    
@l3win make sure to upvote and accept the answer if it helped you. –  Ajasja Feb 8 '13 at 19:43
2  
Check your spelling: It is All, not ALL –  Thomas Feb 8 '13 at 20:11
    
Do you have spaces between the entries in each row? Fortran doesn't do that by default, I know. –  Szabolcs Feb 8 '13 at 20:48
add comment

1 Answer 1

A few possibilities:

data = {{1, 2, 3}, {}, {4, 5, 6}, {}, {7, 8, 9}, {}}

And then any of these should work:

Cases[data, Except[{}]]

Select[data, # =!= {} &]

DeleteCases[data, {}]

data[[1 ;; -1 ;; 2]]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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