Is there a way to import the results or data from Matlab to Mathematica automatically?

点点圈 提交于 2019-12-07 06:13:57

问题


Is there a way to import the results or data (such as matrices) from Matlab to Mathematica automatically? Or is there any way to run a Matlab program first and then run a Mathematica program automatically?

Thanks for any helpful answers!


回答1:


There are at least three approaches to tackling this:

  1. 'Through' Java, using Mathematica's JLink and Matlab's own Java capabilities.

  2. Either program can be run from the command line, execute a script and return output as required. Both programs can run 'external' commands and capture the results. Look, for example, in the Mathematica documentation under the heading External Programs. Matlab has similar capabilities.

  3. If you are running on Linux, or a similar OS, you can pipe the output from one program into the other.

The difficulties of these approaches vary.




回答2:


I stumbled upon this problem and after some tries I managed to create a simple algorithm that worked for me.

Save your matrix in Matlab using:

save('m','-v7','a')

m is the file, -v7 is the version( someone said it would worked better, I don't know) and a is the matrix. I didn't try with more than one matrix at a time.

Then in mathematica I used:

SetDirectory["Desktop"]
a = Import["m.mat"] ;
a=Partition[Flatten[a], 5000]

I set my directory to the location of my m.mat file and imported it. In my case the matrix was 5000*5000 so I had to divided in parts with 5000 elements each. If you have a N*K matrix try to divide by N and K to see what suits your needs.



来源:https://stackoverflow.com/questions/9861642/is-there-a-way-to-import-the-results-or-data-from-matlab-to-mathematica-automati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!