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.


closed as off-topic by Yves Klett, RunnyKine, user9660, m_goldberg, MarcoB Apr 24 '16 at 16:05

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Yves Klett, RunnyKine, Community, m_goldberg, MarcoB
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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"]
  • 1
    $\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.