Where is startup.m supposed to be?

后端 未结 6 2019
旧时难觅i
旧时难觅i 2021-01-31 03:13

I\'ve been chasing the answer to this question in the MATLAB documentation for a long time...

For example, at the bottom of

http://www.mathworks.com/help/matlab/

相关标签:
6条回答
  • 2021-01-31 03:19

    According to this page in the docs, you should create your own startup.m in the "startup directory" which, if you follow the link, leads to this page explaining the definition of "startup directory" in this context.

    You can retrieve this "startup directory" with the userpath function which returns, on my system:

    >> userpath
    
    ans =
    
    C:\Users\MYUSERNAME\Documents\MATLAB;
    

    Personally, I just set the "Start In" in the shortcut to whatever I want - but obviously this won't work if you're not on Windows; if you're not on Windows or prefer not to rely on the shortcut you should create a startup.m with a call to cd in whatever directory userpath returns.

    The docs also say you can modify the userpath function, if you so desire, or the matlabrc.m file in matlabroot/toolbox/local (but you can only do the latter if you're a MathWorks engineer or a system administrator, otherwise MathWorks will rain fiery hell down on you from above, or something...).

    0 讨论(0)
  • 2021-01-31 03:24

    On Mac OS X, you may put your startup.m file in /matlabrootfolder/toolbox/local/. For example, this path might look like the following for Matlab 2012: /Applications/MATLAB_R2012a.app/toolbox/local/.

    To prevent the file from being removed after upgrading Matlab, you may use a symlink to the file. If your startup file is stored at $HOME/myDir/startup.m, for example (in Bash):

    cd /Applications/MATLAB_R2012a.app/toolbox/local/
    ln -s ~/myDir/startup.m .
    

    Reference: http://www.mathworks.com/help/matlab/matlab_env/startup-options.html

    0 讨论(0)
  • 2021-01-31 03:31

    The best method, I find, is this. Let's say you want MATLAB to start up in mystartupdir, and you've placed startup.m in that directory.

    On Windows, make a shortcut icon to MATLAB, then right-click on it and select Properties. Edit the field Start In. Now, use this icon whenever you want to start MATLAB.

    On other platforms, you can run MATLAB with the -sd flag to specify the startup directory:

    matlab -sd mystartupdir

    If you don't specify a startup directory, MATLAB will use the default specified by the userpath command. You can place your startup.m file there.

    0 讨论(0)
  • 2021-01-31 03:32

    For me (I'm using Linux) it worked to put the "startup.m" to the home directory. Apparently, the home directory is by default on the matlab path. Strangely, it also worked when I put the "startup.m" into a newly created "matlab" (must be all lower-case) folder in the home directory. Let me know whether it also works on your system.

    0 讨论(0)
  • 2021-01-31 03:33

    This is meant as a pointer for Lx users (as confused as I was at first...). I work on Debian based boxes, but the same should apply to the CentOS system lineup, etc.

    • Check that after install you do have the directory/ies: ~/.matlab/<yr_release(s)>
      Note that you may have several releases there as is my case. matlab actually permits that.
    • Create ~/.matlab/startup.m
      Incidentally I also created my directory Workspace there. That's completely optional
    • In your Matlab window's Home tab find the menu iten/icon Set Path, click on it and add a "matlab search path" with the button Add folder top left. Add ~/.matlab as a new search path. Change should take effect immediately.
    • Restart Matlab to check that the content of ~/.matlab/startup.m is correctly taken into account at launch time.

    I hate GUIs... I thought you might want to know ;-) HTH.

    0 讨论(0)
  • 2021-01-31 03:43

    As read in http://fr.mathworks.com/help/matlab/matlab_env/matlab-startup-folder.html#buj_13n :

    Changing the Startup Folder

    Starting in R2014b, you can change the startup folder using the General Preferences panel. On the Home tab, in the Environment section, click Preferences. Select MATLAB > General. Choose an option for the Initial working folder.

    By default, the initial working folder is set to Location based on MATLAB startup rules.

    I wish it did not involve the graphical desktop interface, though. By looking closely in the file matlab.setting, which under Linux should lie in ~/.matlab/<your_release>/, you can find the lines

    <key name="UserPath">
        <string>
            <value><![CDATA[<some_directory>]]></value>
        </string>
    </key>
    

    where you can certainly specify manually the startup directory.

    0 讨论(0)
提交回复
热议问题