'ValueError: variable name is not valid in MATLAB' while extracting the results stored in MATLAB workspace after excecuting Simulation in Simulink through python.
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Rasmita
el 11 de Mayo de 2023
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 comentarios
Ver también
Categorías
Más información sobre Call Python from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!