Disable Command Line During Point Selection

4 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Geoff Hayes
Geoff Hayes il 23 Lug 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!

Più risposte (1)

Namita Vishnubhotla
Namita Vishnubhotla il 23 Lug 2014
Modificato: Namita Vishnubhotla il 23 Lug 2014
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:

Categorie

Scopri di più su Entering Commands in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by