Passing a string variable to matlab script from Python using the matlab Python API

5 ビュー (過去 30 日間)
ApprenticeMatlab
ApprenticeMatlab 2018 年 3 月 8 日
回答済み: David Hocker 2020 年 9 月 11 日
Hi, This might be something really simple to someone who have done this, but i am struggling passing a string variable to matlab script from Python using the matlab Python API. I am doing this in 2017b
Here is what i have: 1. Matlab function: config = parseInputs(filename) %filename is a char array in matlab like "config.csv"
2. Python script file which attempts to call the above matlab function. I have saved my function parseInputs.m in the same directory as the python script.
Below is my python script:
import matlab.engine
eng = matlab.engine.start_matlab()
filename = "config.csv"
parameterMy = eng.parseInputs(filename, nargout=2)
I am getting an error like below:
File "C:\ProgramData\Anaconda3\lib\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)
MatlabExecutionError: Undefined function 'parseInputs' for input arguments of type 'char'.
Any hint on how to make it work? Thanks!
  1 件のコメント
per isakson
per isakson 2019 年 6 月 12 日
編集済み: per isakson 2019 年 6 月 12 日
"a char array in matlab like "config.csv" " . Double or single quotes makes a difference
  • "config.csv" is a scalar string
  • 'config.csv' is a character array
However, that might not be relevant to the error you encounter.

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

回答 (2 件)

Eduardo Villalobos
Eduardo Villalobos 2019 年 6 月 12 日
Hey,
did you manage to solve this?
Thanks!

David Hocker
David Hocker 2020 年 9 月 11 日
I had a similar issue, and found that I didn't have the specific matlab function in my current working directory for my python code. Once I moved it there, I was able to get the command to execute. I also used python strings (double quotes, not single) for my string inputs.

カテゴリ

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