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/matlab_env/changing-the-startup-folder.html
it says
Use the startup.m file to specify the startup folder...
...which is plainly absurd, since elsewhere the documentation says that startup.m is to be found in the so-called "startup folder". So therefore there's no way for this file to specify where this folder should be.
Etc., etc., etc. This sort of circularity pervades everything I've found in the docs on startup.m.
What I want to know is: can I or can't I customize the location of the "startup folder" in a way that is persistent, and if so, where is this persistent information stored?
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.
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...).
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
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.
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.
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.
Related
I'm using TFS in Visual Studio 2015, and have a question about MATLAB file associations. For .m files, there is no association to MATLAB, as seen here:
Confusingly, there is an association for .fig and .mat files, so VS must recognise that MATLAB "exists". If I double click one of these file types, it opens it in MATLAB as it would from within an Explorer window. This is the behaviour I want for .m files.
As a minimum, I'd like to have the MATLAB icon for .m files so that they're easy to spot in a directory. As an ideal solution, these files would also open in MATLAB (not the VS text editor) from TFS.
I have tried the "File Extension" option inside of Options > Text Editor, but MATLAB isn't an option for me in the Editor list.
It's worth noting that my work network is pretty strict on software installs, so the fewer external add-ins the better (ideally none). Suggestions appreciated.
There's a utility that I often use to fix OS-level association problems with MATLAB-related files - associateFiles from FEX.
You should probably call it with associateFiles('deleteadd','.m'), which would generate a registry file named MatlabFileAssocFix.reg that has the following contents (obviously the MATLAB path is generated according to your system):
Windows Registry Editor Version 5.00
;FIXES MATLAB FILE ASSOCIATIONS
;REMOVES M FILE ASSOCIATIONS
[-HKEY_CLASSES_ROOT\.m]
[-HKEY_CLASSES_ROOT\MATLAB.m.9.1.0]
[-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.m]
;ADD SHELL OPEN
[HKEY_CLASSES_ROOT\Applications\MATLAB.exe\shell\open\command]
#="\"C:\\D\\Program Files\\MATLAB\\R2016b\\bin\\win64\\MATLAB.exe\" \"%1\""
;ADD M FILE ASSOCIATIONS
[HKEY_CLASSES_ROOT\.m]
#="MATLAB.m.9.1.0"
"Content Type"="text/plain"
"PerceivedType"="Text"
[HKEY_CLASSES_ROOT\.m\OpenWithProgids]
"MATLAB.m.9.1.0"=""
[HKEY_CLASSES_ROOT\.m\PersistentHandler]
#="{5e941d80-bf96-11cd-b579-08002b30bfeb}"
[HKEY_CLASSES_ROOT\.m\Versions\MATLAB.m.9.1.0]
"FileVersionMS"=dword:00090001
"FileVersionLS"=dword:00000000
[HKEY_CLASSES_ROOT\MATLAB.m.9.1.0]
#="MATLAB Code"
"FriendlyTypeName"="#C:\\D\\Program Files\\MATLAB\\R2016b\\bin\\win64\\matlab.exe,-58"
[HKEY_CLASSES_ROOT\MATLAB.m.9.1.0\DefaultIcon]
#="C:\\D\\Program Files\\MATLAB\\R2016b\\bin\\win64\\m.ico,0"
[HKEY_CLASSES_ROOT\MATLAB.m.9.1.0\Shell\Open]
#="Open"
[HKEY_CLASSES_ROOT\MATLAB.m.9.1.0\Shell\Open\command]
#="\"C:\\D\\Program Files\\MATLAB\\R2016b\\bin\\win64\\matlab.exe\""
[HKEY_CLASSES_ROOT\MATLAB.m.9.1.0\Shell\Open\ddeexec]
#="uiopen('%1',1)"
[HKEY_CLASSES_ROOT\MATLAB.m.9.1.0\Shell\Open\ddeexec\application]
#="ShellVerbs.Matlab.9.1.0"
[HKEY_CLASSES_ROOT\MATLAB.m.9.1.0\Shell\Open\ddeexec\topic]
#="system"
[HKEY_CLASSES_ROOT\MATLAB.m.9.1.0\Shell\Run]
#="Run"
[HKEY_CLASSES_ROOT\MATLAB.m.9.1.0\Shell\Run\command]
#="\"C:\\D\\Program Files\\MATLAB\\R2016b\\bin\\win64\\matlab.exe\""
[HKEY_CLASSES_ROOT\MATLAB.m.9.1.0\Shell\Run\ddeexec]
#="run('%1')"
[HKEY_CLASSES_ROOT\MATLAB.m.9.1.0\Shell\Run\ddeexec\application]
#="ShellVerbs.Matlab.9.1.0"
[HKEY_CLASSES_ROOT\MATLAB.m.9.1.0\Shell\Run\ddeexec\topic]
#="system"
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.m\OpenWithProgids]
"m_auto_file"=hex(0):
"MATLAB.m.9.1.0"=hex(0):
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.m\OpenWithList]
"a"="MATLAB.exe"
"MRUList"="a"
When you import this file, it deletes whichever association exists for .m and associates it with MATLAB.
I don't know if this is applicable to your problem, but I thought it should be mentioned.
So after a long time, I've found a reasonable workaround for this.
You can set the "Open With" default for .m files, but this seems to open a new instance of MATLAB for every file - not ideal! Suggested by SACn below their answer.
A better option is to use Visual Studio's "External Tools".
Go to Tools > External Tools, then as this documentation shows, create a new tool. Use the following parameters:
Title: Your Title Here
Command: cmd.exe
Arguments: /c "$(ItemPath)"
Tick "Close on exit". This opens the command prompt with the /c (terminate after command) flag, and runs the file name of the file which you have open in VS. On Windows systems, this will open the file in an open instance of MATLAB, or launch a new one if none exist.
This can be run many ways... Assign a keyboard shortcut, run from the Tools menu, add it to the Toolbar, add it to the context menu.
Now there is one click / key press to launch an open .m file as desired. It still lacks the MATLAB file association (and corresponding icon in the file browser) but does the main job!
Be advised: MATLAB is written in Java and not based on NET or Visual Studio extensions so if we're trying to open MATLAB Editor as plugin this is not a good idea for now.
Now to edit .m files you've to define new (external) default editor for a file type.
And if MATLAB license is not present use Notepad++, Sublime and other free editors which support .m file syntax highlighting.
If I understand correctly, you want to integrate MATLAB with VS (It seems your issue is not TFS related).
There is not such extension for Visual Studio, but there is a MatLab extension for Visual Studio Code.
=========================================================================
From the comment, it seems you want to use team explore in MATLAB to enable integrated use of Team Foundation Version Control. I'm afraid your requirement can't be achieved at this moment. MATLAB doesn't support team explorer or TFS MSSCCI Provider.
I have submitted a user voice at website below, you can vote it:
https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/18325612-enable-integrated-use-of-team-foundation-version-c.
OK, here's how I did it:
I have VS code installed, and as such, it creates an association in my default programs like this:
Then you can just point your VS program at this extension:
For example: Rstudio uses so called projects - text files ending with .Rproj. When you click on a project file, it opens up Rstudio and sets working dir to where the project file is. Optionally, it executes any code written it. However, it does not open itself (i.e., it does not show up in the script editor).
Is there something like that in Matlab? If not, how to emulate it?
Currently I use to make an .m file with cd, addpath calls etc. But when I click in the file browser:
it just opens Matlab and shows up in the script editor without running
opening Matlab is what I want, but showing up in the script editor is actually redundant; I only need to run it (and use the results in my Matlab desktop session)
(What I want to avoid is having to open the script file, run it manually and then having to close it again. It is annoying!)- edited
Matlab does not have "project files" (as far as I know).
However, I think you can easily emulate what you want.
Let's suppose you have your code in a folder C:\MyProject:
1) Create a new m-file C:\MyProject\MyProject.m with all your initialization code (cd, addpath calls, global variables, whatever you need).
Here's a simple example for demonstration purposes:
disp('Replace this with your initialization code');
2) Create a batch-file C:\MyProject\MyProject.bat as follows:
MATLAB -r "run MyProject"
Now, by double-clicking the batch-file you will:
open the complete Matlab environment
execute the script MyProject.m (without loading it in the script editor)
For this purpose, MATLAB offers startup.m files (online documentation).
You have to put all your initialization code in a file called startup.m, which needs to be located within the MATLAB search path (i.e. within your project folder). The script will be executed every time you open MATLAB by double-clicking a arbitrary m-file from your project folder.
I have been trying to use "stateflow chart" block for hours. However, I keep getting this error:
The current directory is c:\program files\matlab13\bin, which is reserved for MATLAB files. Please change your current directory to a writable directory preferably outside of MATLAB installation area.
What I have done:
moved the model from bin to my E:\drive but nothing is going good.
But did you actually change directories. For example typing in the command window:
cd('E:\drive');
You could also change your current directory by changing the current folder from the second menu bar at the top of the Matlab window. If you do it either way, you should be no longer in the Matlab installation area and the first error message should not appear. If things are still not working out, you will have to share the new error message with us.
For documentation I need ca. 100 times a day the path of the selected/current subsystem.
That means I need some field where I can copy and past the path to use it in a document.
I just know and find the way with the Model Browser. But I have to typ the whole path.
As already stated, the currently selected block or subsystem can be retrieved by using gcb. But it is also possible to copy this directly into the clipboard. Therefore select the to be copied block and use the clipboard command:
clipboard('copy', gcb);
You can also create a Matlab shortcut (right click on the "Shortcut" toolbar and select "New Shortcut") or even a Simulink menu entry with according keyboard shortcut (search Simulink documentation for "sl_customization") for this command, if you use it that frequently.
My default input method has always been configured this way:
(setq default-input-method "russian-computer")
Something broke, and all I get is this message (on top of the execution stack, if I'm interpreting it right) as soon as I press C-\:
activate-input-method: Can't activate input method `russian-computer'
It used to work without a hitch. There has been no intervention that I'm aware of; I'd like to get some clues.
Emacs loads the input-methods it knows from a directory called "leim" (Library of Emacs Input Methods). The location of the code to load should be something like
/usr/share/emacs/<version>/leim/leim-list.el
(For the exact location, search for an entry containing the word "leim" in your load-path variable by typing C-h v load-path.)
If you inspect that file, you should see an entry
(register-input-method
"russian-computer" "Russian" 'quail-use-package
"RU" "ЙЦУКЕН Russian computer layout"
"quail/cyrillic")
which refers to a subdirectory of the "leim" directory called "quail".
Make sure that both the file leim-list.el and the sub-directory quail exist on your system. The quail directory is distributed separately from the Emacs source code, so if you installed from source, make sure you included the leim-list package. See here (scroll to bottom):
http://ftp.gnu.org/pub/gnu/emacs/
If the leim directory is empty, you might consider re-installing emacs.