MATLAB Answers

How to add a specific path to Matlab in -batch mode?

14 views (last 30 days)
Ye Cao
Ye Cao on 20 Jul 2021
Answered: Steven Lord on 20 Jul 2021
I have two questions.
1)I need to run matlab in a remote server. The running mode is matlab -batch. Is there a way to add a search path to Matlab when it starts?
2)The matlab -batch “script” command seems to start Matlab each time for running a script. Is it possible to load matlab into memory without reloading matlab every time?
Thanks a lot.

Answers (2)

Bjorn Gustavsson
Bjorn Gustavsson on 20 Jul 2021
To my understanding and brief testing (Ubuntu, 2020a) it should work by simply adding paths as normal in/from your batch-script:
% In batch_job.m
addpath /home/you/matlab/batch_project/subdir -end % etc
Then the /home/you/matlab/batch_project/subdir directory will be at the end of the matlab-path when running:
matlab -batch batch_job

Steven Lord
Steven Lord on 20 Jul 2021
For your first question, if you know you're always going to want this directory on the MATLAB path when you start your batch job you could add it to the path and save that path using addpath and savepath.
For your second question, if you're using Microsoft Windows opening MATLAB as a COM Automation Server may be helpful.


Community Treasure Hunt

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

Start Hunting!

Translated by