Disable Command Line During Point Selection
5 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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!
0 个评论
更多回答(1 个)
Namita Vishnubhotla
2014-7-23
编辑:Namita Vishnubhotla
2014-7-23
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:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Entering Commands 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!