I am trying to pass a matrix variable from MATLAB to python, but I am only acquiring the first element of that matrix in python. Does anyone know can get the full matrix?
Python
import sys
if __name__ == '__main__':
x = sys.argv[1]
print x
MATLAB
A = magic(5);
[str,err] = sprintf('/usr/local/python name_of_program.py %d ', A);
unix(str)
Look at the contents of str: /usr/local/python name_of_program.py 17 /usr/local/python name_of_program.py 23 /usr/local/python name_of_program.py 4 ...
When you pass a 5x5 matrix to sprintf, it reproduce the formatting string 25 times, with one of the elements substituted for the %d, in order (column by column).
I suggest another way to transfer data between the programs, such as writing it to a file. If you really want to pass everything on the command line, try the following:
A_str = sprintf(' %d',A);
str = strcat('/usr/local/python name_of_program.py ',A_str);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With