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!
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!
There are at least three approaches to tackling this:
'Through' Java, using Mathematica's JLink and Matlab's own Java capabilities.
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.
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.
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.