Disable Command Line During Point Selection

조회 수: 3 (최근 30일)
Jacob
Jacob 2014년 7월 23일
편집: Jacob 2014년 7월 23일
I'm trying to use datacursormode to select a two points on a 3D plot. The point selection is working just fine. However, I'm using 'pause' to wait for the user to click a point. The problem is that 'pause' requires you to press a key to continue. This is activating my command window, switching me from my program GUI to view the code, and I have to switch back to my GUI before I can click the next point.
Is there either a way to disable the command window so that "pressing a key to continue" does not enter a command; or an alternative to 'pause' that continues upon the mouse being clicked?
I'm using R2014a on Windows 7.
Some relevant code:
dcm_obj = datacursormode(handles.mainfig);
set(dcm_obj, 'Enable', 'on', 'SnapToDataVertex', 'off');
pause
f = getCursorInfo(dcm_obj);
selpt1 = f.Position;
Thanks!
EDIT: I adapted my own solution from Geoff's suggestion:
f1 = struct;
dcm_obj1 = datacursormode(handles.mainfig);
set(dcm_obj1, 'Enable', 'on', 'SnapToDataVertex', 'off');
f1 = getCursorInfo(dcm_obj1);
while isempty(f1) || isempty(fieldnames(f1))
pause(0.01);
f1 = getCursorInfo(dcm_obj1);
end
selpt1 = f1.Position;
datacursormode off;
f2 = struct;
dcm_obj2 = datacursormode(handles.mainfig);
set(dcm_obj2, 'Enable', 'on', 'SnapToDataVertex', 'off');
f2 = getCursorInfo(dcm_obj2);
while isequal(f1, f2)
pause(0.01);
f2 = getCursorInfo(dcm_obj2);
end
selpt2 = f2.Position;
datacursormode off;
This allows two independent points to be selected and used.

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 7월 23일
An alternative to pause may be to use a form of polling as described at http://undocumentedmatlab.com/blog/waiting-for-asynchronous-events. Something like
dcm_obj = datacursormode(handles.mainfig);
set(dcm_obj, 'Enable', 'on', 'SnapToDataVertex', 'off');
delay = 0.01; % 10 milliseconds
% until a point is selected, f will be empty
f = getCursorInfo(dcm_obj);
while isempty(f)
pause(delay);
f = getCursorInfo(dcm_obj);
end
selpt1 = f.Position;
Try the above and see what happens!

추가 답변 (1개)

Namita Vishnubhotla
Namita Vishnubhotla 2014년 7월 23일
편집: Namita Vishnubhotla 2014년 7월 23일
Use the "uiwait" command instead of pause. You can find the documentation for uiwait here.
You can then use the "WindowButtonDownFcn" property of the figure to assign a callback, where you can handle the data collection and also call uiresume ( documentation link ).
For example:
function foo
f = figure;
set(f,'WindowButtonDownFcn',@(~,~) myFun);
uiwait
disp('Done waiting')
end
function myFun
% data collection
disp('myFun');
uiresume;
end
Follow the link below to the documentation page on Function Handle Callbacks:

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by