How can I pass control back to the MATLAB command prompt after keyboard command?

조회 수: 5 (최근 30일)
K E
K E 2016년 4월 20일
댓글: dpb 2018년 2월 2일
I am debugging some code and have inserted a keyboard command into a loop. The code generates a figure, then when it hits the keyboard command control is passed to the editor (if I start typing, text appears in the code). Instead I would like to pass control to the command window after the keyboard command (if I start typing, text would appear at the command prompt). I tried using commandwindow before the keyboard command, but that did not seem to override the keyboard command's default of passing control to the code. What do you suggest?
for i = 1:50
figure;
commandwindow;
keyboard;
end
  댓글 수: 2
Donna Calhoun
Donna Calhoun 2017년 12월 10일
Before version 2017a, the script below would immediately return control to the prompt. But starting with 2017a, this script returns control to the editor the first time the keyboard statement is hit; the second time, though, control is returned to the prompt.
This is really annoying, because we use this feature in a library routine. As the OP pointed out, immediately typing upon hitting 'k' (in the example below) edits the library file (our 'key_test.m') file. One has to then undo any typing in the library file that was inadvertently edited, then click to focus on the command window.
% key_test.m
inp = 'k';
while(strcmp(inp,'k'))
inp = input('Input k or q : ','s');
switch inp
case 'k'
keyboard;
case 'q'
return
end
end
Is there any chance this will be fixed? Or is this now a "feature"?
dpb
dpb 2018년 2월 2일
While some age on it; issues still abound...
R2016b/Win 7 (and I think earlier are same) when the breakpoint in editor is reached focus is switched to the editor window while the debug prompt appears in the command window. Invariably, one wants focus in the command window but typing as noted above immediately destroys the existing file.
To make matters even worse, now a CTRL-Z to undo will go PAST the changes made to those prior to the previous SAVE so you can actually undo previous corrections.
All in all, a complete cock-up and why, in general, tended to not use the Matlab editor/debug facility nearly as much as could.

댓글을 달려면 로그인하십시오.

답변 (1개)

per isakson
per isakson 2016년 4월 21일
편집: per isakson 2016년 4월 21일
I failed to make my system, R2016a on Win7, behave as you describe. On the contrary it behaves exactly as you want it to do.
The command, keyboard, makes Matlab switch to debug-mode and if I start typing text it appears in the command window after the prompt, K>>. When I move the cursor over the editor window it switches to the spinning wheel. Clicking in the editor allows me to type code. &nbsp
  댓글 수: 4
per isakson
per isakson 2016년 4월 21일
편집: per isakson 2016년 4월 22일
Now I have tried your example with commandwindow.
I just typed cssm and then dbcont three times without touching the mouse. Same behavior when I started with&nbsp Run Selection. This example shows expected and wanted behavior on my system, R2016a on Win7.
>> cssm
K>> dbcont
K>> dbcont
K>> dbcont
>>
where
function cssm()
for jj = 1:3
figure;
commandwindow
keyboard
end
end
K E
K E 2016년 4월 22일
If you are getting the desired behavior (control passed to the command window) on R2016a, and I am not on R2015b/Win 7, I will see if this will be fixed by updating my version.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Desktop에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by