Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีเรียกฟังก์ชัน Python จาก MATLAB

MATLAB รุ่น 2014b ขึ้นไปรองรับการเรียก Python libraries โดยตรง ใช้ prefix py. นำหน้าชื่อ library

ตัวอย่าง

py.calendar.isleap(2016)  # ans = 1
py.calendar.isleap(2017)  # ans = 0

สำหรับฟังก์ชันของตัวเอง สร้างไฟล์ hello.py ใน current working directory:

def world():
    return 'hello world'

ใน MATLAB เรียก py.hello.world() จะได้ Hello world!