Pregunta

I'm having difficulties importing matrices into Mathematica and Maple. The format of the file looks like this:

     0.0000000 1.0000000 1.0000000 
     1.0000000 1.0000000 0.0000000 
     1.0000000 0.0000000 0.0000000 

When imported into mathematica with:

    In[1]:= Import["Matrix1.txt", "Table"]

    Out[1]:= {{0.0000000 1.0000000 1.0000000}, {1.0000000 1.0000000 0.0000000}, {1.0000000 0.0000000 0.0000000}}

And from there it doesn't respond to Mathematica functions. And obviously looks incorrectly imported.

Also in Maple:

  > A = ImportMatrix["Maple_Matrix1.txt", source=delimited]
  >
  > A
  > syntax error, missing operator or ';':

More issues importing.

Importing to either would be great. Each one has a set of built-in functions I want to use.

¿Fue útil?

Solución

Any of the following should work in at least Maple versions 14 through 17, for the plaintext data that you've shown. Only the last two would work in Maple 13.

Note the use of round brackets rather than square brackets in the function calls.

Note the semicolon (or colon, to suppress printing the result as output) as statement terminator. That is required for 1D Maple notation input.

ImportMatrix("Maple_Matrix1.txt", source=MATLAB, mode=ascii);

ImportMatrix("Maple_Matrix1.txt", source=MATLAB, mode=ascii);

ImportMatrix("Maple_Matrix1.txt", delimiter=" ");

ImportMatrix("Maple_Matrix1.txt", source=delimited, delimiter=" ");

Note also that the syntax for assignments in Maple is :=, not =. The latter only creates an equation (and doesn't assign to anything, by itself). So you would want, say,

A := ImportMatrix("Maple_Matrix1.txt", delimiter=" ");

Otros consejos

Your matrix looks like it is being processed as a string at the moment. Try running after the importHead[%[[1]]] and it might say it is a string. If it was a list then Head[%[[1]][[1]]] might should it is a real. Are your files tab or space delimited? You might have to try a ReadList["FILE",{Number,Number,Number}]

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top