Clear Filters
Clear Filters

Calling a matlab script with arguments on the linux commandline

84 views (last 30 days)
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 Comments
Paul
Paul on 10 Jan 2021
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 on 10 Jan 2021
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.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 10 Jan 2021
~/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 Comments
Walter Roberson
Walter Roberson on 3 Feb 2021
"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 on 3 Feb 2021
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!