2
$\begingroup$

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?

$\endgroup$
4
  • 4
    $\begingroup$ Have a look at "IgnoreEmptyLines" here reference.wolfram.com/mathematica/ref/format/Table.html $\endgroup$ – Ajasja Feb 8 '13 at 19:26
  • $\begingroup$ All right, thanks guys, I got it. $\endgroup$ – l3win Feb 8 '13 at 19:38
  • 2
    $\begingroup$ Check your spelling: It is All, not ALL $\endgroup$ – Thomas Feb 8 '13 at 20:11
  • $\begingroup$ Do you have spaces between the entries in each row? Fortran doesn't do that by default, I know. $\endgroup$ – Szabolcs Feb 8 '13 at 20:48
8
$\begingroup$

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]]
$\endgroup$

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.