Export matlab workspace data to python

조회 수: 24 (최근 30일)
i want to export matlab workspace data to python and plot the graph in python
eng.sim("add.slx")
myVar = eng.workspace["out.simout.Data"]
print(myVar)
but i am getting this ValueError: variable name is not valid in MATLAB.
Could anyone please help me to solve this?
  댓글 수: 1
Urveshkumar Dharmendrabhai
Urveshkumar Dharmendrabhai 2023년 5월 2일
I am trying to control and simulate the simulink model through Python. However, I am getting the same error as below:
'ValueError: variable name is not valid in MATLAB'
I have written below code:
def getOutput(self):
simout_S = self.eng.workspace['out.simout']
tout_T = self.eng.workspace['out.tout']
return simout_S, tout_T
The error which I got is related the workspace variable. The workspace variable 'simout' is already defined in the simulink model.
How can I solve this problem? How can I extract results stored in the workspace into Python and plot them at the end?
For more information about my question, kindly see my question posted on the link below:
https://de.mathworks.com/matlabcentral/answers/1956564-valueerror-variable-name-is-not-valid-in-matlab-while-extracting-the-results-stored-in-matlab-wor

댓글을 달려면 로그인하십시오.

채택된 답변

Indhu Priyadharshini Govindasamy
Indhu Priyadharshini Govindasamy 2021년 12월 16일
eng.eval('a = out.simout;',nargout=0)
mpi = eng.workspace['a']
print(mpi)
adding eval worked for me

추가 답변 (1개)

Sanjay Sivakumar
Sanjay Sivakumar 2021년 12월 14일
You can try to export the MATLAB workspace data to an excel spreadsheet and use the spreadsheet in python.
  댓글 수: 1
Indhu Priyadharshini Govindasamy
Indhu Priyadharshini Govindasamy 2021년 12월 14일
Thank you for your reply. i will try this
@Deepak Meena replied like we can use this line of code to access the workspace variable in python.
p = eng.workspace['out.simout'];
but i dont know why it is not working in my case.

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by