1

I read some files in Python as follows:

with open("C:\Users\MyUser\Downloads\testPicture.jpg", 'rb') as FID:
    fileInBytes = FID.read()

This returns a bytes string in Python.

Running type(fileInBytes) returns <class 'bytes'>.

I need to call a Python function from MATLAB. The Python function expects the file instance as a bytes string, as described above. So, I would need to do the following in MATLAB:

  • Read in file from MATLAB in format, which will map, when calling a Python function from MATLAB, as a bytes string.

From this document, I believe, uint8 in MATLAB converts to bytes in Python.

How can I achieve this? I'm guessing I just need to read a file in uint8 format in MATLAB and pass that into Python

2
  • Have you tried your own suggestion? Commented Apr 25, 2022 at 23:13
  • I haven't been able to find reading uint8 in Matlab from a file Commented Apr 25, 2022 at 23:21

1 Answer 1

1

According to the fopen manual page, files are opened in binary mode unless t is in the permission string.

According to fread manual page, precision, there is reading into uint8:

fread(fid, '*uint8');

Presto.

Sign up to request clarification or add additional context in comments.

2 Comments

This should work: data = fread(fid, '*uint8');
@AliÖzgürArgunşah Edited.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.