フィルターのクリア

problems when using scipy.opti​mize.diffe​rential_ev​olution in Matlab environment

5 ビュー (過去 30 日間)
Reinhardt RADING
Reinhardt RADING 2023 年 6 月 2 日
編集済み: Walter Roberson 2023 年 6 月 4 日
When i call a matlab function to be optimized with the inputs arguments i get 'not enough input' error.
For example; i have a matlab function called Residual.m that requires 5 input and returns one value.
Residual(state, N, freq, SNR, p)
My code is like this:
py_optimize = py.importlib.import_module('scipy.optimize');
N=2
bound = [-50, 500; -50, 500; -150, 150];
x_bound = repmat(bound, N, 1);
freq=10; SNR=30;
p=1;
data=py_optimize.differential_evolution(Residual,x_bound,disp=True, maxiter=4500, popsize=65, init='random', workers=worker, recombination=0.8, mutation=nn, strategy='best1bin', tol=0.001, updating='deferred');
When i run this, i get an error that there is not enough inputs.
I tried using matlabFunction with my fuction but i keep getting below error
Error using indexing
Handle to MATLAB function '@()' is not supported. Use a handle to a Python function.
What I'm i not doing right?

回答 (1 件)

Al Danial
Al Danial 2023 年 6 月 4 日
scipy.optimize.differential_evolution() expects a Python function as its first argument. You'll need to translate Residual.m to Python, then pass this translated function as the first argument. I suppose in theory you could provide a Python wrapper to Residual.m then use the matlab.engine from Python to call Residual.m but I've not been successful with that combination.

カテゴリ

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

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by