Using matlab engine in python, error with config_io

9 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Call 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