Calling a user function from Python gives error
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call MATLAB from Python 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!