matplotlibがインポートされているユーザー定義のpythonをSimulink上で実行するとエラー発生
4 views (last 30 days)
Show older comments
matplotlibがインポートされているユーザー定義のpythonをSimulink上で実行するとエラー発生します。
matlab再起動直後に発生します。matlabワークスペース上でmatplotlibのインポートは可能です。
暫定的にはmatplotlibを使用しない事としようと思いますが、
一度エラーが発生してしまうとユーザー定義関数が使用できなくなります。
トラブルの原因になるため、matlabの設定等で恒久的に対処する方法はありませんか?
【実行環境】
・Windows 10
・MATLAB R2021a update 6(最新アップデート)
・Python 3.8.10
【simulinkモデル】

【MATLAB Function内のコード】
function y = fcn(u)
coder.extrinsic('test_plt')
test_plt
y = u;
【pythonモジュール呼び出し関数】test_plt.m
function test_plt()
py.test_matplotlib.dammycal(1,2)
end
【pythonのユーザー定義関数】test_matplotlib.py
import matplotlib.pyplot as plt
def dammycal(a,b):
return a+b
【エラーメッセージ】

2 Comments
交感神経優位なあかべぇ
on 4 Jul 2022
Windows11, MATLAB R2021b, R2020a、Python 3.8, Python 3.7環境でそれぞれ上記モデルを作成し、実施してみましたが、私の環境では正常に動作してしまい、原因の特定ができませんでした。
エラーが発生してしまったPython定義関数ですが、下記ページの「変更されたユーザー定義 Python モジュールの再読み込み」の手順に従うことで、再度使用可能になります。
Answers (0)
See Also
Categories
Find more on MATLAB の Python ライブラリ in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!