Why can MATLAB engine session no longer call "clear all"?

29 visualizaciones (últimos 30 días)
Gabalodon
Gabalodon el 7 de Oct. de 2025 a las 0:03
Comentada: Gabalodon el 7 de Oct. de 2025 a las 16:01
Between MATLAB 2024b and MATLAB 2025a, feeding a "clear all" call to a MATLAB engine (opened with engOpen() or engOpenSingleUse()) prevents any subsequent MATLAB code from executing properly within the engine.
For example, in MATLAB's engdemo.cpp:
if (!(ep = engOpen(""))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
return EXIT_FAILURE;
}
// Add clear all call
engEvalString(ep, "clear all");
Adding the "clear all" call causes all subsequent MATLAB calls (including the plot, and setting the X variable) to not work. This worked fine up to and including MATLAB 2024b.

Respuestas (1)

Walter Roberson
Walter Roberson el 7 de Oct. de 2025 a las 0:10
It would not surprise me at all if "clear all" is clearing some crucial connection information that has been stored in variables.
You should expect problems if you "clear all". Using "clear all" is like Wile E. Coyote blowing up the very bridge that he is standing on.
  3 comentarios
Walter Roberson
Walter Roberson el 7 de Oct. de 2025 a las 0:49
In my opinion, it always relied upon undefined behaviour, and it should not be surprising if the results of that undefined behaviour changed over time.
Gabalodon
Gabalodon el 7 de Oct. de 2025 a las 16:01
But in theory, shouldn't a "clear all" command only affect Matlab variables within the engine? It shouldn't impact the connection between C++ and the engine, and it shouldn't prevent new Matlab variables from being created within the engine. And if it can impact the engine, then that should be documented and it should execute an engClose to release the engine.

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by