'ValueError: variable name is not valid in MATLAB' while extracting the results stored in MATLAB workspace after excecuting Simulation in Simulink through python.
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Rasmita
il 11 Mag 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 Commenti
Vedere anche
Categorie
Scopri di più su Call Python from MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!