MATLAB (từ R2014b) hỗ trợ gọi trực tiếp thư viện Python qua tiền tố py..
Gọi module Python chuẩn
py.calendar.isleap(2016) % ans = 1 (true)
py.calendar.isleap(2017) % ans = 0 (false)
Gọi hàm tự viết
Tạo file hello.py trong thư mục làm việc MATLAB:
def world():
return 'hello world'
Trong MATLAB:
py.hello.world() % ans = 'hello world'
Yêu cầu
- Python cài đặt trên cùng máy.
- MATLAB tìm thấy Python (có thể cấu hình bằng
pyenv). - File .py phải trong MATLAB search path hoặc current folder.
Chuyển đổi kiểu dữ liệu
MATLAB tự chuyển đổi kiểu cơ bản: number, string, list/tuple -> cell array, dict -> struct...