'ValueError: variable name is not valid in MATLAB' while extracting the results stored in MATLAB workspace after excecuting Simulation in Simulink through python.
8 次查看(过去 30 天)
显示 更早的评论
I would like to control my Simulink model using Python. I have written a Python script for it. My simulink model name is = 'ToyExample_V2'. The model is shown below in the picture attached.
In this model, using Python, I want to give '1' as an input value to the constant block and I would like to run the simulation for 10 seconds with the timestep value 0.1. At the end of the simulation, I would like to see the results stored the workspace which has variable stored as a name 'simout'.
In order to extract the results from Matlab workspace, I have written a Function (method) in the Python as shown below:
However, after running the code, I am getting the error 'variable name is not valid in MATLAB' as shown below:
def getOutput(self):
simout_S = self.eng.workspace['out.simout']
tout_T = self.eng.workspace['out.tout']
return simout_S, tout_T
0 个评论
回答(1 个)
Rasmita
2023-5-11
Hi,
As per my understanding, you would like to access the ‘out.simout’ and ‘out.tout’ workspace variables in your Python script, but you are getting the error 'variable name is not valid in MATLAB' for these variables.
To understand the issue, you have to note that ‘out.simout’ is a way to access the time-series data for a single signal stored in a structured array (‘out’) that contains the simulation results that have been saved to the MATLAB workspace using the ‘To Workspace’ block in Simulink.
So, the correct syntax to access these variables in Python are as follows:
simout_S = self.eng.workspace['out']['simout']
tout_T = self.eng.workspace['out']['tout']
For more information, please refer to the below documentation links:
Hope this helps!
Regards,
Rasmita
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!