MATLAB Answers

Is there a way (command line switch) to prevent execution of startup.m when starting a new Matlab instance?

50 views (last 30 days)
Matthias on 21 Oct 2016
Answered: Eric Condamine on 5 Jul 2019
Is there a way (command line switch) to prevent execution of startup.m when starting a new Matlab instance? How about the same for finish.m?

Accepted Answer

Jan on 21 Oct 2016
Edited: Jan on 21 Oct 2016
You can write a small batch job, which creates an envorinment variable before calling Matlab:
@echo off
set NoMatlabStartupM=1
Now insert this on top of the startup.m function:
NoMatlabStartupM = getenv('NoMatlabStartupM');
if ~isempty(NoMatlabStartupM)
No startup.m is still called, but not executed, when you start Matlab through this batch file.

More Answers (4)

Image Analyst
Image Analyst on 23 Oct 2016
You could write a temporary file in your startup.m to some known location. If the file exists, just exit the startup, but if not, write the file. Have a finish.m file where you delete the file when MATLAB (any instance) exits.
folder = 'c:\users\public\Documents'; % Wherever...
fullFileName = fullfile(folder, 'MATLAB is running.txt');
if exist(fullFileName, 'file')
% MATLAB is already running. So just exit the startup.m
% File is not there and MATLAB is not running.
fid = fopen(fullFileName, 'wt');
fprintf('MATLAB started at %s', datestr(now));
Then in your finish.m file, which runs when you exit MATLAB, delete that file.
folder = 'c:\users\public\Documents'; % Wherever...
fullFileName = fullfile(folder, 'MATLAB is running.txt');
if exist(fullFileName, 'file')
Image Analyst
Image Analyst on 26 Oct 2016
When I ran one after the other had already started, it was no problem. If you tried to launch both at about the same time, you'd need to check which instance was the one that actually ran the startup.m file.

Sign in to comment.

Matthias on 18 Nov 2016
Thanks for your answers! What I meant with "self-contained" is that the suppression of startup.m-execution would only apply to individual Matlab instances as needed, without modifying anything on the system (which might break other users' stuff). My use case is that I want to spawn new Matlab processes from within my main Matlab session for some background processing, but I don't want those processes to run startup.m (e.g. to speed up startup or because they should have a different path environment anyway). It would be nice to have a command line option like
matlab -nodesktop -nosplash -noStartupFileExecution
For now, I run a check in the startup/finish files whether the current instance was started with the -nodesktop option (usejava('desktop')), which happens works for my use case and is simple, but not as general as your solutions.
  1 Comment
Steven Lord
Steven Lord on 18 Nov 2016
That sounds like a reasonable enhancement request to file with Technical Support. You can do so using the Contact Us link in the upper-right corner of this page. Please include the use case so that Support can capture it for the developers' future reference in the enhancement database entry.

Sign in to comment.

Eric Condamine
Eric Condamine on 3 Jul 2019
After more than two years, is there now a way to launch matlab without using our personal startup.m and if possible our personal finish.m, by using only a special argument like -noStartupFileExecution? In fact it seems to be not too complicated, because it is like we start using only the default startup.m and finish.m file ...
Rik on 3 Jul 2019
Technically that isn't the same as starting a session without running startup.m, but I can't think of an example of when the difference would matter. (unless running this would still run startup.m secretly, I'm on mobile so I can't check, but it would necessarily surprise me)
Note that the -r syntax has been available since at least ML6.5, and probably way before that.

Sign in to comment.

Eric Condamine
Eric Condamine on 5 Jul 2019
The problem is just to start matlab without using the personal startup.m (et finish.m) file of the user, and for all platforms (not only Windows). I am developing a python app where I need to do somethings in matlab and catch the result (without using intermediate file, etc. I try to be as simple as possible). It will be easier to use the standard output from matlab, but in this case there are the usual starting Matlab message (from matlab_path/VersionInfo.xml file) all stuffs that can generate a display, from the user startup.m file. So It will be nice if a special matlab option exist (like -noStartupFileExecution as proposed by Matthias above) to start matlab in the "just after install way" (i.e. the default startup.m, finish.m, default path etc ...). Because right now, I need to use a workaround like the one below to do something that would be very easy to do if this option existed!
I use the python subprocess library to deal with the call system, stdout, stderr, etc ... So this is multiplatforms (I guess, because I develop only on real OS, so Linux and MacOS ;-
As an example a way to ask the version of matlab knowing the matlab_path and the spm path. I use the stderr possibility of fprintf to overcome the statup.m, finish.m, etc that I discussed above ...
matlab_path -nodisplay -nodesktop -nosplash -singleCompThread -r "addpath(spm_path); [name, ~]=spm('Ver'); fprintf(2, '%s', name(4:end)); exit" > /dev/null


No tags entered yet.

Community Treasure Hunt

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

Start Hunting!

Translated by