필터 지우기
필터 지우기

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

조회 수: 29 (최근 30일)
Adam Hicks
Adam Hicks 2017년 11월 13일
댓글: Stephen23 2023년 11월 29일
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
Adam Hicks
Adam Hicks 2017년 11월 13일
!"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 2017년 11월 13일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Hicks
Adam Hicks 2017년 11월 13일
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
ME
ME 2023년 11월 29일
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 2023년 11월 29일
"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), ')"'])

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by