问题描述
R有一个很棒的快捷方式,它可以运行光标当前所在的行,然后将光标移至下一行( cmd + return
).在 matlab 中,您必须突出显示该行,然后运行突出显示的部分 (shift + F7
).
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
).
是否有创建"R like"运行线快捷方式的方法?我正在使用OSX.
Is there a way to create an 'R like' run line shortcut? I'm using OSX.
推荐答案
-
在主页"选项卡上,单击新建",然后选择命令快捷方式".
On the Home tab, click New, and then select Command Shortcut.
在标签"字段中:输入快捷方式的名称.在回调"字段中:
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];
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];
现在,我可以通过按Alt + s + 1来运行我所在的行(也许您可以将其更改为任意热键).我希望这会有所帮助.
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.
在MATLAB R2018a命令快捷方式已重新打包为收藏夹命令" .因此,要在此版本和更高版本中创建新的快捷方式,您需要进入首页"标签->收藏夹->新的收藏夹.
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.
您当前(在MATLAB R2020b中)可以使用Alt + 1运行此代码(不需要上面的's').但是,它在首选项"->设置"中似乎是不可更改的.键盘->快捷方式
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
这篇关于创建Matlab运行行快捷方式(如R)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!