Using Python with the MATLAB engine, how can I supress the warning
54 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Eric Laurendeau
el 6 de En. de 2026 a las 4:45
Editada: Eric Laurendeau
el 9 de En. de 2026 a las 15:21
I'm using Python to fetch some block's mask parameter. Those parameter are string with no evaluation of value needed.
Every time I try to load the model, I receive those warning:
Warning: Error evaluating 'PreLoadFcn' callback of block_diagram 'LibraryTest'.
Callback string is 'LibraryTest_init;'
> In load_system>i_load_system (line 44)
In load_system (line 20)
Warning: Unrecognized function or variable 'LibraryTest_init'.
> In load_system>i_load_system (line 44)
The Python script is not in the model folder, as such, those warning are expected as the init file is with the model.
Is there a way to just supress those warning in python so that they don't print?
4 comentarios
Broy
el 9 de En. de 2026 a las 8:15
Use nargout = 0 to explicitly tell Python not to expect a return value.
eng = matlab.engine.start_matlab()
try:
% 1. Save the current warning state directly into the MATLAB workspace.
eng.eval("previousState = warning;", nargout=0)
% 2. Turn off warnings.
eng.warning('off', 'all', nargout=0)
% Rest of the Code
finally:
% 3. Restore the warning state
if eng.workspace.get('previousState'):
eng.eval("warning(previousState);", nargout=0)
% Rest of the Code
Eric Laurendeau
el 9 de En. de 2026 a las 15:18
Editada: Eric Laurendeau
el 9 de En. de 2026 a las 15:19
Respuestas (0)
Ver también
Categorías
Más información sobre Call Python from MATLAB en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!