Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Matlab run line shortcut (like R)

Tags:

macos

matlab

R has a great shortcut that runs the line your cursor is currently on then moves the cursor onto the next line (cmd + return). In matlab, you have to highlight the line then run the highlighted section (shift + F7).

Is there a way to create an 'R like' run line shortcut? I'm using OSX.

like image 467
James Owers Avatar asked Oct 02 '14 14:10

James Owers


People also ask

What is the shortcut for run in MATLAB?

And it's a pretty simple MATLAB shortcut. For MAC as the command key (⌘) and return or F5 on other platforms. If you don't want to run the whole code, select a fragment and press F9 instead for PC or function and F9.

What does Ctrl R do in MATLAB?

To customize a keyboard shortcut: Open the Keyboard Shortcuts Preferences page in the Preferences Window and, in the search box, type an existing keyboard shortcut or the name of an action, tool, or menu. For example, you can type Ctrl+R (shortcut), Delete (action), Command Window (tool), or File (menu).

How do I create a shortcut in MATLAB?

You can create a shortcut to the desktop or you can add MATLAB to your Start Menu. To create a shortcut, right-click on matlab.exe and select “Send to >” and then select “Desktop (create shortcut)”. To add MATLAB to the Start Menu, right-click on matlab.exe and select “Pin to start.”


1 Answers

  1. On the Home tab, click New, and then select Command Shortcut.

  2. In the Label field: enter a name for the shortcut. In the Callback field:

    currentEditor = matlab.desktop.editor.getActive; originalSelection = currentEditor.Selection; assert(originalSelection(1)==originalSelection(3)); currentEditor.Selection = [originalSelection(1) 1 originalSelection(1) Inf]; disp(currentEditor.SelectedText); eval(currentEditor.SelectedText); currentEditor.Selection = originalSelection + [1 0 1 0];

Now I can run the line I'm on by pressing Alt+s+1 (perhaps you can change this to an arbitrary hotkey). I hope this helps.

EDIT: In MATLAB R2018a Command Shortcuts have been repackaged as Favorite Commands. So to create a new shortcut in this and later version, you need to go Home tab -> Favorites -> New Favorite.

EDIT: You currently (in MATLAB R2020b) can run this code with Alt+1 (no need for 's' as above). However, it does not appear to be changeable in Preferences -> Keyboard -> Shortcuts

like image 50
jkazan Avatar answered Oct 02 '22 14:10

jkazan