Hello,
I use a batch script to start Matlab and set the startup directory via the -sd switch.
Example:
:: Matlab startup directory
set STARTUP_DIRECTORY=
:: Matlab Executable
set MATLAB_EXECUTABLE=
:: start Matlab with specified startup directory
call "%MATLAB_EXECUTABLE%" -sd "%STARTUP_DIRECTORY%"
I use this procedure because I work with multiple Matlab configurations (Java classpath, Java library path, Matlab path) in each of the startup directories.
I have a setup script which collects all required information and stores the 3 Matlab configuration files (javaclasspath.txt, javalibrarypath.txt, pathdef.m) in the startup directory. To get that directory in the current Matlab session i used the following (dirty but working) code:
char(java.lang.System.getProperty('user.dir'));
But since Matlab 2019a, this line always returns:
'C:\Users\<UserName>\Desktop'
I have also tried the userpath command but unfortunately, this always returns the same directory, no matter which directory is specified as startup directory:
'C:\Users\<UserName>\Documents\MATLAB'
Maybe someone has got a solution or workaround for my problem?
Thank you,
Markus