Python       脚本语言

MATLAB    商业数学软件

Python调用MATLAB

一开始是使用的这种 在win上用的
MATLAB Engine API for Python
https://ww2.mathworks.cn/help/matlab/matlab-engine-for-python.html
后来需要部署到linux上 需要 MATLAB_Runtime 和 MATLAB打包并且编译成Python App
https://ww2.mathworks.cn/help/compiler_sdk/gs/create-a-python-application-with-matlab-code.html

使用 MATLAB 中的 polyfit(x,y,n) 多项式曲线拟合 
做成定时任务版本的 自动化脚本

为什么使用Python

其实java C++  什么的 MATLAB  都有提供驱动包 都可以使用 但是 Python 目前来讲这种库多一点即使不使用 MATLAB 的函数库 也可以很简单的找到其他的函数库
使用Python调用 MATLAB 的函数库的原因是没有时间验证Python的其他科学库是否有效
MATLAB 提供免费的MATLAB_Runtime 环境 用来运行MATLAB 打包编译的 MATLAB 程序 
相关的参考文档   以下皆为MATLAB 官方文档

生成 Python 包并构建 Python 应用程序

https://ww2.mathworks.cn/help/compiler_sdk/gs/create-a-python-application-with-matlab-code.html

各种语言集成MATLAB 的教程

https://ww2.mathworks.cn/help/compiler_sdk/python_packages.html?s_tid=CRUX_lftnav
启动 MATLAB Engine for Python
https://ww2.mathworks.cn/help/matlab/apiref/matlab.engine.start_matlab.html

调用打包的 MATLAB 函数

https://ww2.mathworks.cn/help/compiler_sdk/python/evaluate-a-compiled-matlab-function.html
首页
https://ww2.mathworks.cn/matlabcentral/?s_tid=gn_mlc

学习部署时应严格遵守相关版本的文档

目前验证的是 MATLAB R2021b Runtime  Python3.8.17 部署在linux 环境下 是正常运行的
 CentOS Linux release 7.9.2009 (Core)

遇到的错误

大概意思是 linux自带的一些库和MATLAB_Runtime  的一些库版本高低的问题  
安装完MATLAB_Runtime 会修改掉一些linux库的引导路径 这个是公司运维解决的

export LD PRELOAD=matlabroot/bin/glnxa64/glibc-2.17 shim.so

社区首页 有问题先看社区

首页
https://ww2.mathworks.cn/matlabcentral/?s_tid=gn_mlc

MATLAB_Runtime 和Python 在linux上联调就遇到这一个错误
https://ww2.mathworks.cn/support/search.html/answers/868193-segmentation-fault-when-using-matlab-engine-with-rhel-or-centos-linux.html?fq[]=asset_type_name:answer&fq[]=category:matlab/call-python-libraries&page=1

posted on 2023-07-24 14:53  高海峰  阅读(64)  评论(0编辑  收藏  举报