Using matlab engine in python, error with config_io

10 ビュー (過去 30 日間)
Soraya B
Soraya B 2023 年 3 月 30 日
コメント済み: Soraya B 2023 年 4 月 3 日
Hi everyone,
I am currently setting up a matlab engine on python. It is working fine and I could launch some matlab scripts from python.
Yet, there are one specific matlab script that I CANNOT run from python as I get this error :
Unrecognized function or variable 'config_io'.
I do not read any error when running the script directly from matlab, nor do I when I run the script from matlab engine on python while removing that specific line.
Any advice on how to fix this ? The line config_io is really important to my script as I am working with EEG and triggers... Should I try to find a way to use config_io in python before launching the matlab engine ?
(Using matlab 2022b and python 3.11 on Windows)
Thanks in advance fro your answers,
Regards.

採用された回答

Shubham
Shubham 2023 年 4 月 3 日
Hi Soraya,
The error you are encountering is due to a missing function or variable in your MATLAB path when running the script from Python. The function or variable 'config_io' might not be accessible from the MATLAB engine when running the script from Python.
One possible solution could be to add the directory containing the necessary MATLAB function or variable to your MATLAB path before running the script from Python. You can do this by using the addpath function in MATLAB. For example, if the directory containing the necessary function or variable is located at C:\path\to\directory, you can add it to the MATLAB path as follows:
addpath('C:\path\to\directory')
You can add this line of code to your MATLAB script before the line that uses the 'config_io' function or variable.
Alternatively, you could implement the functionality of 'config_io' in Python using available libraries or by writing your own code. This might be a better solution if you need to run the script on multiple platforms or if you want to avoid dependencies on MATLAB.
  1 件のコメント
Soraya B
Soraya B 2023 年 4 月 3 日
Thanks a lot, it worked !
I am putting here what I have done in case it can help others.
%know the path to add
which config_io
Then adding to my script :
if run_from_python == 1
% need to add the path to config_io otherwise will raise error
% you might need to modify your path, to find the right path in a
% terminal do : which config_io
disp("Adding path to config_io")
addpath("C:\Toolboxes\io64\")
end
config_io

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by