call matlab function from python but the argument is always mismatch

5 ビュー (過去 30 日間)
dh tang
dh tang 2019 年 12 月 20 日
コメント済み: dh tang 2020 年 5 月 11 日
I want to call fanbeam, the function defines in matlab like
proj = fanbeam(image, 1075,...
'FanSensorGeometry', 'arc',...
'FanSensorSpacing',0.1, ...
'FanRotationIncrement', 360/320);
At first I call the fanbeam in python like
proj = eng.fanbeam(image,1075.0,nargout=3)
it works well,But I want add some argument 'FanSensorGeometry', 'FanSensorSpacing',so I try to wrap them as a dict then pass the dict to fanbeam
para_dic = {"FanSensorSpacing":0.1,"FanRotationIncrement" :360.0/320}
proj = eng.fanbeam(hello,1075.0,para_dic,nargout=3)
But I got a wrong message
File "/media/Data/MyModel/train.py", line 118, in <module>
proj = eng.fanbeam(hello,1075.0,para_dic)
File "/home/wd/anaconda3/lib/python3.7/site-packages/matlab/engine/matlabengine.py", line 71, in __call__
_stderr, feval=True).result()
File "/home/wd/anaconda3/lib/python3.7/site-packages/matlab/engine/futureresult.py", line 67, in result
return self.__future.result(timeout)
File "/home/wd/anaconda3/lib/python3.7/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:
File /usr/local/MATLAB/R2019b/toolbox/images/images/private/check_fan_params.m, line 20, in check_fan_params
File /usr/local/MATLAB/R2019b/toolbox/images/images/fanbeam.m, line 168, in fanbeam
Function FANBEAM expected an even number of parameter/value arguments.
So,What should I do to pass these arguments to fanbeam function from python?
  1 件のコメント
Matt J
Matt J 2019 年 12 月 20 日
Note: For years, fanbeam has exhibited weird non-linear behavior, which nobody seems to understand. I wouldn't trust it.

サインインしてコメントする。

採用された回答

Shrinidhi KR
Shrinidhi KR 2020 年 5 月 8 日
You can just call it and specify the parameters directly, it worked for me.
import matlab.engine
eng = matlab.engine.start_matlab()
I = eng.eval('ones(100)')
D = eng.eval('200')
dtheta = eng.eval('45')
proj = eng.fanbeam(I, D,'FanSensorGeometry', 'arc','FanSensorSpacing',0.1,'FanRotationIncrement',dtheta)
I have used eval to avoid any datatype mismatch from matlab into python. Alternatively you can try to call fanbeam function inside eval function as well, but have to handle the string quotations properly

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall MATLAB from Python についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by