keep focus in command window

조회 수: 17 (최근 30일)
Andrew
Andrew 2013년 9월 25일
답변: Jim Hokanson 2020년 5월 26일
how can I keep keyboard focus in the command or edit window, even if I create, change or clf a figure?
or to ask another way: how can I prevent figures stealing my focus?
I'm using linux.
thanks

채택된 답변

Walter Roberson
Walter Roberson 2013년 9월 25일
Avoid using figure() without any arguments. Create axes explicitly and parent them against the figure. Parent all plotting elements explicitly against the axes (or figure, as appropriate.) Do not use figure(ID) to switch attention to that figure: if you need to switch attention then set(0,'CurrentFigure',ID). But with parenting explicitly the circumstances under which you will need to do that will be reduced.
  댓글 수: 1
Andrew
Andrew 2013년 9월 25일
I didn't understand all of what you said, but
set(0, 'CurrentFigure', ID)
solves my problem. Thank you!

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

추가 답변 (1개)

Jim Hokanson
Jim Hokanson 2020년 5월 26일
You could also create a function that does what you want. In response to Walter's answer, I don't want to always work at avoiding calls to figure ... You can call this function at the command line and it will keep focus in the command line
function fig(h)
%
% TODO: Document - replaces figure(h)
if nargin == 0
figure();
else
figure(h);
end
%Not sure what the best option is here but we need
%to wait until some point when Matlab has switched focus to the
%figure before switching back to the command window otherwise due to the
%asynchronous nature we'll "switch" to the command window and then Matlab
%will switch to the figure
drawnow nocallbacks
commandwindow
end

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by