why does Matlab return ' expression to the left of the equals sign is not a valid target'

2 ビュー (過去 30 日間)
Charles
Charles 2017 年 9 月 5 日
回答済み: Robert Snoeberger 2017 年 9 月 6 日
I am using MATLAB 2017a and Python 3.6 I am trying to call a Python script from within the MATLAB window and assign the returned variables to the MATLAB workspace.
I am told by MATLAB help desk that MATLAB does support this version of Python, contrary to what their website says. I have copied my Python folder to my MATLAB pathway as follows:
insert(py.sys.path,int32(0), '/Users/....../Oandafx');
I now attempt to execute the following command in the MATLAB command window
N = py.oandafx.get_history('EUR_USD', granularity='D', prices='BA', count=5)
I get the following error. Can you tell me where I am going wrong?
Error: The expression to the left of the equals sign is not a valid target for an assignment.

回答 (2 件)

Robert Snoeberger
Robert Snoeberger 2017 年 9 月 6 日
MATLAB doesn't support keyword arguments [1]. To pass keyword argument to Python, use pyargs [2].
Example:
N = py.oandafx.get_history('EUR_USD', pyargs('granularity','D','prices','BA','count',5))
  1. https://docs.python.org/2/tutorial/controlflow.html#keyword-arguments
  2. https://www.mathworks.com/help/matlab/ref/pyargs.html

Walter Roberson
Walter Roberson 2017 年 9 月 5 日
It is not legal to have '=' inside MATLAB expressions. You probably need to do a bunch of quoting.
  2 件のコメント
Charles
Charles 2017 年 9 月 5 日
What do you mean. "A bunch of quoting"?
James Tursa
James Tursa 2017 年 9 月 5 日
E.g., you can't have this as a literal argument:
count=5
You might have to quote the whole thing like this
'count=5'
Same for the other arguments with equal signs. It will depend on what form py.oandafx.get_history accepts.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by