Filter löschen
Filter löschen

'ValueError: variable name is not valid in MATLAB' while extracting the results stored in MATLAB workspace after excecuting Simulation in Simulink through python.

11 Ansichten (letzte 30 Tage)
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

Antworten (1)

Rasmita
Rasmita am 11 Mai 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

Kategorien

Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by