Hey,
I wrote some sample code to interface MATLAB - PyTorch/Libtorch by the use of C++ and Libtorch.
I did it because for our application it was not an option to write to binary and load it (because of performance issues).
You can find the sample code here:

  
      
      GitHub
  
  
    

Haydnspass/PytorchMatlabBind 35

This repo shows a minimal and still alpha-version example of how to interface Matlab and PyTorch. - Haydnspass/PytorchMatlabBind


  
  
    
    
  
  


As I am rather new to C++, the code is by no means clean, but it (should) work.
The CMakeLists.txt builds an arbitrary shared dummy library as well as the actual interface which will be a .mex file for the use in MATLAB.
Cheers,
Lucas