1
$\begingroup$

Lets say I have an array defined as:

Array1 = ConstantArray[0, {1, 3, 3}];
Array1[[1, 1, 2]] = 5;
Array1[[1, 1, 3]] = t;

How could I export this array since it is a combination of numerics and symbols, I don't know how to do that. I appreciate for your help.

Ahmet

$\endgroup$
  • 1
    $\begingroup$ Save the notebook. Then set the directory to the notebook directory. SetDirectory@NotebookDirectory[]. After this use Export["file.txt",Array1] $\endgroup$ – Sâu Oct 23 at 11:52
1
$\begingroup$

The best answer for you is going to be heavily dependent on what exactly you'd like to do with it once you have it exported. Do you want to be able to re-import it into Mathematica later? Do you want to be able to re-import it into Mathematica on a different computer? Do you want to be able to read the exported matrix using a program other than Mathematica?

If you just want to be able to export the matrix and re-import it into any copy of Mathematica, this is what I would do:

Export["~/Desktop/Array1.xml", Array1]
array2 = Import["~/Desktop/Array1.xml"]
Array1 == array2
(* True *)

As a side note, try to avoid capitalizing your variable names. Built-in functions in Mathematica always begin with a capital. If you avoid beginning your variable name, then you should never accidentally use the same name as a built-in function. This especially important in cases like E = 5. This will fail since E is already defined.

$\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.