Calling a user function from Python gives error

2 ビュー (過去 30 日間)
Peppe
Peppe 2020 年 4 月 2 日
編集済み: Peppe 2020 年 4 月 2 日
Hi,
I have user Matlab function. It is written by someone else. There are multiple functions in that file but the first function that has the same name as the .m file itsel is the one that I try to call. It gets 4 arguments (string, string, string, boolean).
Usually in Matlab I call it like this: function('string', 'string, true)
When trying in Python I use following code.
The error I get is following:
Error using resimPrepareNewVersion
Too many output arguments.
Too many output arguments.
I don't understand the error. I already give the same arguments as in Matlab. Even when I give it 3, 2, or no arguments I get the same error. When Matlab loads this functions are loaded automatically so I don't need to add path but I did it any way. However, I tried without giving any path. Code generation and starting Matlab goes without any problem. In Matlab this function loads some other files and opens a info dialog it it means anything.
def CodeGenerationAndResim(self, Models=None, Resim=False, Type='TW'):
""" This function checks out the Simulink models and
and generates code. It compares the generated coode
with the already checked code.
All variables:
Models - All Sim Modelto generate c code for
Resim - Running Resim function
Type - Type of Resim archive
matlabEngine - Matlab engine to start Matlab
MatlabEngineSuccessfull - Checks if Matlab engine is started without error
CodeGenSuccessfull - Checks if Code Generation is successsful
ResimSuccessfull - Checks if Resim function is performed successfully.
"""
# Check variables
MatlabEngineSuccessfull = True
CodeGenSuccessfull = True
ResimSuccessfull = True
# Call Matlab engine
try:
matlabEngine = matlab.engine.start_matlab('-nodesktop', background = False)
matlabEngine.addpath("C:\\temp")
except EngineError as e:
MatlabEngineSuccessfull = False
Print("Could not start Matlab. Do you have Matlab 64 bits installed?")
# Generate code
if Models is not None and MatlabEngineSuccessfull:
for model in Models:
try:
matlabEngine.rtwbuild(model)
except Exception as e:
CodeGenSuccessfull = False
print('Something went wrong')
# Running Resim
if Resim and MatlabEngineSuccessfull and CodeGenSuccessfull:
try:
matlabEngine.resimPrepareNewVersion('all','Model2',1)
except Exception as e:
ResimSuccessfull = False
print(e)

回答 (0 件)

カテゴリ

Help Center および File ExchangeCall MATLAB from Python についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by