Borrar filtros
Borrar filtros

How to run a .m file in a new MATLAB instance?

29 visualizaciones (últimos 30 días)
Adam Hicks
Adam Hicks el 13 de Nov. de 2017
Comentada: Stephen23 el 29 de Nov. de 2023
I'm running a script which calls several functions, and one of these only works in a new version of MATLAB (R2016b). I'm trying to get my version of MATLAB (R2010b) to open a new instance of 2016b MATLAB and run a script within it to finish my program. I currently have:
!"C:\Program Files\MATLAB\R2016b\bin\matlab.exe" NewFunction.m
which opens a new instance of MATLAB R2016b but does not execute NewFunction.m within it (or at all).
  2 comentarios
Adam Hicks
Adam Hicks el 13 de Nov. de 2017
!"C:\Program Files\MATLAB\R2016b\bin\matlab.exe" -r NewFunction.m &
This tells the new MATLAB instance to run NewFunction using CLI.
However, it seems that it is trying to run NewFunction.m before MATLAB fully starts up and says, "Undefined variable "NewFunction" or class "NewFunction.m"".
Is there a way I can tell MATLAB to wait before executing the command? As far as I know this functionality doesn't exist in Unix/CLI.
Steven Lord
Steven Lord el 13 de Nov. de 2017
When you use the -r flag, whatever is after it should be a valid MATLAB command. "NewFunction.m" is not, unless m is a MATLAB program file inside a package named NewFunction or is a Static method of a class named NewFunction.
If you want to execute a MATLAB program file named NewFunction.m you would need "path_to\matlab.exe -r NewFunction" since NewFunction is what you would type in the MATLAB Command Window to execute that program file.

Iniciar sesión para comentar.

Respuesta aceptada

Adam Hicks
Adam Hicks el 13 de Nov. de 2017
I found the solution here .
!"C:\Program Files\MATLAB\R2016b\bin\matlab.exe" -r "NewFunction"
This will run NewFunction.m on startup in the new instance of MATLAB.
  5 comentarios
ME
ME el 29 de Nov. de 2023
this handles inputArg1 as a string... you could try buidling this command via eval and strcat:
inputArg1 = 1;
eval(['!"C:\Program Files\MATLAB\R2016b\bin\matlab.exe" -r "NewFunction(' num2str(inputArg1) ')"'])
Stephen23
Stephen23 el 29 de Nov. de 2023
"you could try buidling this command via eval and strcat:"
Do NOT do that. Call the SYSTEM function. For example:
system(['"C:\Program Files\MATLAB\R2016b\bin\matlab.exe" -r "NewFunction(',num2str(inputArg1), ')"'])

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by