Personal Blog where I share my professional learnings. Oriented towards productivity tricks including AutoHotkey, Microsoft Office 365 (Microsoft Teams, Microsoft Outlook, Excel, Word, SharePoint, OneDrive), VBA, books, Blogger, Jira, Confluence, Power BI,...
September 7, 2016
MATLAB Editor: customized Shortcuts
It is possible to add Shortcuts in the MATLAB Editor for customized actions.
I take as example in this post the nice utility in the File Exchangeplot_depfun.
1. Function returning current file in Editor
For this you need a utility function that returns the current opened file in the MATLAB Editor.
You can find this function below:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2. Adapt function to take as default input file the current file in the Editor
Then you need to adapt the function to be run by the Shortcut to take by default the current file in editor, calling previous utility function.
You need to add something like the lines below:
if nargin==0||isempty(foo),
foo= EditorGetFile();
end
at the top of the file.
(My full modified plot_depfun version is available in Gist here.)
3. Create the Shortcut
You can create a Shortcut in the MATLAB Toolbar as explained in the& MATLAB documentation. See screenshot below:
Create Shortcut with "Add to quick access toolbar"
Simply put a call to the plot_depfun function as Callback: this will take the current file in the Editor (see modification done in Step 2.)
If you haven't implemented in the function the default used file as EditorGetFile (Step 2), you could also simply use here as Callback plot_depfun(EditorGetFile);.
Important: Check the option "Add to quick access toolbar". This will make the Shortcut visible also in the MATLAB Editor as shown in next screenshot in the so-called Quick Access Toolbar:
Shortcut is accessible from Editor Quick Access Toolbar
Hint 1: You can organize the Shortcuts (re-order, add separators etc.) by right-clicking on the Toolbar and select the last context menu entry "Customize...".
Hint 2: The file located under fullfile(matlabroot, 'toolbox/matlab/icons','plotpicker-dendrogram.png') is used as icon for the plot_depfun shortcut.