Disable Command Line During Point Selection
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (1)
Namita Vishnubhotla
el 23 de Jul. de 2014
Editada: Namita Vishnubhotla
el 23 de Jul. de 2014
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:
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!