2014-10-02 75 views
12

R有一個很棒的快捷方式,它可以運行光標當前所在的行,然後將光標移動到下一行(cmd + return)。在matlab中,您必須突出顯示該行然後運行突出顯示的部分(shift + F7)。創建Matlab運行線快捷方式(如R)

有沒有辦法創建一個'喜歡'運行線快捷方式?我正在使用OSX。

+5

通常,我所做的是用%%行和CTRL + ENTER分隔特定部分以運行該特定代碼段。 – 2014-10-02 14:59:43

+1

這是一個很好的解決方法,但僅僅因爲我想測試一行代碼而亂扔我的代碼會非常麻煩。我真的很感興趣,看看有沒有人能夠做出這樣的捷徑。 – kungfujam 2014-10-02 15:02:00

+4

在調試模式下,您可以像這樣逐步執行代碼。要只運行一行,雙擊該行(應突出顯示整行),然後F9運行它。 – Dan 2014-10-02 15:13:59

回答

7

1)在主頁選項卡上,單擊新建,然後選擇命令快捷方式。

2)在標籤字段中:輸入快捷方式的名稱。 回調領域:

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(或許你可以將其更改爲任意熱鍵)就行了。我希望這有幫助。

+0

這個工程!這些命令的參考在哪裏?我想讓它在運行後光標移動到下一行。 – kungfujam 2016-03-22 08:52:46

+0

好聽!試試從這個鏈接找到你的方式:http://blogs.mathworks.com/community/2009/10/26/the-matlab-editor-at-your-fingertips/ – JCKaz 2016-03-22 09:54:25

+0

也許這也可以讓你感興趣@Ander Biguri – JCKaz 2016-03-22 10:00:31

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