필터 지우기
필터 지우기

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

조회 수: 11 (최근 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

답변 (1개)

Rasmita
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

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by