MATLAB: Keyboard shortcut to evaluate current line

keyboard shortcutsMATLAB

I often use a keyboard shortcut to evaluate highlighted selections of a script I'm working on. But often, I will add a single line to a script and want to evaluate it right away. To do this I highlight the line and hit F9, but it would be a smoother process if I could simply hit F10 to evaluate the line my cursor is on without needing to highlight the line. I've checked the Preferences and I don't see this option available. Are there any clever hacks to allow this?
I'm using R2012b on a Mac.

Best Answer

Create a Quick Access Toolbar shortcut for doing this and call it "Run line". Here's the code:
currentEditor = matlab.desktop.editor.getActive;
originalSelection = currentEditor.Selection;
assert(originalSelection(1)==originalSelection(3));%Check that multiple lines are not selected
currentEditor.Selection = [originalSelection(1) 1 originalSelection(1) Inf];%Select the whole line
eval(currentEditor.SelectedText);%Run the whole line
currentEditor.Selection = originalSelection;%Reset selection to original state
clear currentEditor originalselection
Now, press and hold the Alt key (at least in Windows) to see the mnemonics for the Quick Access Toolbar items. On my system a little "5" shows for the "Run line" shortcut.
Hence I can press Alt+5 to run the current line and leave my selection unchanged. Alternatively I could use the mouse to click the "Run line" button on the Quick Access Toolbar.
-Eric