how can I import matrix of 3 dimentional vector from a txt file? I know how to import simple matrix of number, but I dont know how to import matrix of vectors and what type of data should be in my file. I'm exporting data into .txt file in my C program. I used pattern like

 {numbers} {numbers}


{numbers}, {numbers}

but I dont get matrix imported in mathematica.

  • 1
    $\begingroup$ Give us an example of how the data is stored in the file. What format is the file, first of all? $\endgroup$ – MarcoB Apr 23 '16 at 18:50
  • $\begingroup$ @MarcoB I've edited my question and added some examples I used. $\endgroup$ – Sergei Podlipaev Apr 23 '16 at 19:08
  • 1
    $\begingroup$ @Sergei Podlipaev I don't believe you understood what MarcoB was asking for. Is the contents of your text file 3.7,2.6<carriagereturn><newline> or is it 3.7<tab>2.6<newline> or is 3.7<space>2.6<space><carriagereturn> or is it... $\endgroup$ – Bill Apr 23 '16 at 19:35

If you have flexibility in choosing your txt file data format, then you can work backwards.

Start by constructing the objects you want in Mathematica. For example, a list of vectors:

testObject=Tuples[{0, 1}, 3]
(*{{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 1},...,{1, 1, 1}}*)

Then export this into a text file with a convenient format (such as CSV):

Export["test.txt", testObject, "csv"]
(* file will look like: "0,0,0<CR><LF>0,0,1<CR><LF>0,1,0<CR><LF>..."*)

Now, if you format your C-program output like this txt file, it should be easy to import as follows:

Import["test.txt", "csv"]
| improve this answer | |
  • 2
    $\begingroup$ Easier and better: Export["test.csv"] and Import["test.csv"]. Mathematica will recognize the format from the file extension. $\endgroup$ – m_goldberg Apr 24 '16 at 14:49

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