I have a txt file with space-delimited x, y, z coordinates of several points. The points are organized into groups of unequal size; the groups are delimited by skipping a line, like this:

2.3 3.4 5.5
2.4 3.3 5.6
2.5 3.5 5.6

1.2 4.3 3.3
0.7 4.0 3.5

-1.2 1.3 -0.7
-1.1 1.7 -0.5

I can't find a way to have Mathematica just import these then plot the points! I've tried searching a little bit but didn't find a similar question.

When plotting, it's not important to distinguish from which group each point came from. For example, I don't need different colours for each group or anything like that.


I would use:

dat = ReadList["file.txt", Number, RecordLists -> True];

ListPointPlot3D[dat, PlotStyle -> PointSize[Large]]

Mathematica graphics

"file.txt" is of course the name (and if necessary the path) of your data file.

Thanks to the default option NullRecords -> False any extra lines are omitted from dat.

dat = Import["F:/data.txt", "Table"] /. {} -> Sequence[];
  • 1
    $\begingroup$ Even better is the option of import "IgnoreEmptyLines"->True $\endgroup$ – Ajasja Feb 27 '13 at 14:33
  • 1
    $\begingroup$ @Ajasja with that option this is a good method for data types that ReadList does not easily recognize. For regular numeric data it's bound to be slower than ReadList however. $\endgroup$ – Mr.Wizard Feb 27 '13 at 14:52

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.