问题描述
当我在m文件中定义要在Simulink中使用的变量时(预先定义了action1和action2)
% action1=1
% action2=2
set_param('try11/Constant2','Value','action2')
set_param('try11/Constant','action1')
sim('try11.slx')
s1=try11/Constant
没有错误报告,并且模拟开始。 try11只是一个简单的Simulink文件,其中添加了“ Constant2”(action2)和“ Constant”(action1)。但是,当我尝试在Python中运行以下代码时。
eng = matlab.engine.start_matlab()
eng.workspace['action2'] = matlab.double([0.0])
eng.workspace['action1'] = matlab.double([1.0])
eng.tryy(nargout=0)
reward = eng.eval('ans.output')
print(reward)
我收到以下错误消息。
Error using tryy (line 3)
The block diagram 'try11' is not loaded. Traceback (most recent call last): File "/home/majid/anaconda3/lib/python3.8/site-packages/IPython/core/interactiveshell.py",line 3343,in run_code
exec(code_obj,self.user_global_ns,self.user_ns) File "<ipython-input-2-06fc4fb2fc97>",line 1,in <module>
runfile('/home/majid/PycharmProjects/reinforcementlearning/Main_Directory/mattry.py',wdir='/home/majid/PycharmProjects/reinforcementlearning/Main_Directory') File "/snap/pycharm-professional/218/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py",line 197,in runfile
pydev_imports.execfile(filename,global_vars,local_vars) # execute the script File "/snap/pycharm-professional/218/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py",line 18,in execfile
exec(compile(contents+"\n",file,'exec'),glob,loc) File "/home/majid/PycharmProjects/reinforcementlearning/Main_Directory/mattry.py",line 13,in <module>
eng.tryy(nargout=0) File "/home/majid/anaconda3/lib/python3.8/site-packages/matlab/engine/matlabengine.py",line 70,in __call__
return FutureResult(self._engine(),future,nargs,_stdout,File "/home/majid/anaconda3/lib/python3.8/site-packages/matlab/engine/futureresult.py",line 67,in result
return self.__future.result(timeout) File "/home/majid/anaconda3/lib/python3.8/site-packages/matlab/engine/fevalfuture.py",line 82,in result
self._result = pythonengine.getFEvalResult(self._future,self._nargout,None,out=self._out,err=self._err) matlab.engine.MatlabExecutionError: Invalid Simulink object name: try11/Constant2.
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)