Disable Command Line During Point Selection
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Geoff Hayes
le 23 Juil 2014
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 commentaires
Plus de réponses (1)
Namita Vishnubhotla
le 23 Juil 2014
Modifié(e) : Namita Vishnubhotla
le 23 Juil 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:
0 commentaires
Voir également
Catégories
En savoir plus sur Entering Commands dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!