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 $4 \times N$ matrix in a .txt file of the form:

-17.071 137.567 16.554 0.65

-16.873 136.138 16.934 0.7

-15.397 135.738 16.894 0.7

-14.7 135.982 15.9 0.6

... ($N-4$ additional row entries)

Where the numeric values in each row are separated by a space. How would I read this matrix in, and parse it in the following manner:

{ 
  {-17.071, 137.567, 16.554, 0.65},
  {-16.873, 136.138, 16.934, 0.7},
  {-15.397, 135.738, 16.894, 0.7},
  {-14.7, 135.982, 15.9, 0.6},
  ...
}

Evaluating

Import[PATH\\MATRIX.txt]] 

Only returns the printed contents of the file.

share|improve this question
    
Please upload the file somewhere so that we can help you better. –  s0rce Mar 6 '13 at 22:38
1  
Related? –  cormullion Mar 6 '13 at 22:41
add comment

1 Answer

up vote 5 down vote accepted

I suspect that

data = Import[PATH\\MATRIX.txt, "Table"]

could work for you, however, I'm not sure without a copy of your file. If you post that I will try to update this answer.

share|improve this answer
    
Works! ReadList[PATH\\MATRIX.txt, {Number, Number, Number, Number}] also worked. –  Roger Harris Mar 6 '13 at 22:40
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.