필터 지우기
필터 지우기

Calling a matlab script with arguments on the linux commandline

조회 수: 80 (최근 30일)
Paul
Paul 2021년 1월 9일
댓글: Steven Lord 2021년 2월 3일
I am trying to call a matlab script which takes a single argument (a file path), loads and generates plots from the data. I am hitting the "Error: Invalid use of operator." error, even though this script runs fine within a matlab GUI instance, what am I doing wrong?
(base) bash-4.2$ ~/apps/MATLAB/R2020b/bin/matlab -nosplash -nodesktop -r "~/git/oceanObs/evaluate/make_levels.m('~/Shared/200428_data_OceanObsAnalysis/200913_210216_local_robust_1950_FLRdouble_sptg_200913_79pres1000.mat');"
MATLAB is selecting SOFTWARE OPENGL rendering.
< M A T L A B (R) >
Copyright 1984-2020 The MathWorks, Inc.
R2020b Update 3 (9.9.0.1538559) 64-bit (glnxa64)
November 23, 2020
To get started, type doc.
For product information, visit www.mathworks.com.
/home/duro/git/oceanObs/evaluate/make_levels.m('/home/duro/Shared/200428_data_OceanObsAnalysis/200913_210216_local_robust_1950_FLRdouble_sptg_200913_79pres1000.mat');
|
Error: Invalid use of operator.
  댓글 수: 3
Paul
Paul 2021년 1월 10일
Surely, with Matlab 2020b Update 3 you can use underscores (char 95) within directory and file names? Please don't tell me that I have to add a preceding \?
Paul
Paul 2021년 1월 10일
Ok that doesn't seem to be it:
(base) bash-4.2$ ~/apps/MATLAB/R2020b/bin/matlab -nosplash -nodesktop -r "make_levels.m /work/durack1/Shared/200428\_data\_OceanObsAnalysis/200913\_210216\_local\_robust\_1950\_FLRdouble\_sptg\_200913\_79pres1000.mat;"
MATLAB is selecting SOFTWARE OPENGL rendering.
< M A T L A B (R) >
Copyright 1984-2020 The MathWorks, Inc.
R2020b Update 3 (9.9.0.1538559) 64-bit (glnxa64)
November 23, 2020
To get started, type doc.
For product information, visit www.mathworks.com.
make_levels.m /work/durack1/Shared/200428\_data\_OceanObsAnalysis/200913\_210216\_local\_robust\_1950\_FLRdouble\_sptg\_200913\_79pres1000.mat;
|
Error: Invalid text character. Check for unsupported symbol, invisible character, or pasting of non-ASCII characters.

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

채택된 답변

Walter Roberson
Walter Roberson 2021년 1월 10일
~/apps/MATLAB/R2020b/bin/matlab -nosplash -nodesktop -r "cd('~/git/oceanObs/evaluate');make_levels('~/Shared/200428_data_OceanObsAnalysis/200913_210216_local_robust_1950_FLRdouble_sptg_200913_79pres1000.mat');"
Or better yet,
~/apps/MATLAB/R2020b/bin/matlab -batch "cd('~/git/oceanObs/evaluate');make_levels('~/Shared/200428_data_OceanObsAnalysis/200913_210216_local_robust_1950_FLRdouble_sptg_200913_79pres1000.mat');"
  댓글 수: 8
Walter Roberson
Walter Roberson 2021년 2월 3일
"Execute MATLAB script, statement, or function non-interactively. MATLAB:
Starts without the desktop
Does not display the splash screen
Executes statement
Disables changes to preferences
Disables toolbox caching
Logs text to stdout and stderr
Does not display modal dialog boxes
Exits automatically with exit code 0 if script executes successfully. Otherwise, MATLAB terminates with a non-zero exit code.
statement is MATLAB code enclosed in double quotation marks. If statement is the name of a MATLAB function or script, do not specify the file extension. Any required file must be on the MATLAB search path or in the startup folder.
Use the -batch option in non-interactive scripting or command line work flows. Do not use this option with the -r option.
To test if a session of MATLAB is running in batch mode, call the batchStartupOptionUsed function.
Example: -batch "myscript"
Steven Lord
Steven Lord 2021년 2월 3일
MATLAB does what you tell it to do not what you want it to do. Basically whatever you specify with -r or -batch is run as though you typed it in the Command Window.
Rather than using cd as Walter did consider using the -sd startup option to specify the directory in which MATLAB should start.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by