I'm currently trying to save an array as a bin file in Matlab, send it to Python and read it in Python. However, when I run it, Matlab shows errors. I use the following codes:
Read the array in Matlab, convert to bin file and go to Python:
array1 = rand(5,1); %% array1 is the desired array that needs to be sent to Python
fid = fopen('nazmul.bin','wb'); %% I want to save array1 in the nazmul.bin file
fwrite(fid,array1);
status=fclose(fid);
python('squared.py','nazmul.bin'); %% I want to send the parameters to squared.py program
file squared.py:
import sys
if __name__ == '__main__':
f = open("nazmul.bin", "rb")
try:
byte = f.read(1)
while byte != "":
byte = f.read(1)
finally:
f.close()
print byte
However, when I run this program, nothing is printed. I think the bin file is not getting the squared.py file properly.
Thanks for your feedback.
Nazmul
source
share