How can I control the while loop iterations using a pushbutton and selecting data using datacursormode upon each iteration?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
**How can I control the while loop iterations with a pushbutton (to make it stop the loop) where in each loop iteration I am selecting data in a plot using datacursormode?
Here is my code that I have so far just as an example. It seems to work for the most part except it doesn't save the data I select on the 2nd iteration, which I can't correct.**
%% Here is the code below
fig = figure z = peaks; plot(z(:,30:35)) next=1 ButtonHandle = uicontrol('style','push', 'callback','next=0','userdata',0) ; newStat=[]; numberofselections=1
while next==1
dcm_obj = datacursormode(fig);
set(dcm_obj,'DisplayStyle','datatip',...
'SnapToDataVertex','off','Enable','on')
disp('Click line to display a data tip, then press Return.')
% % Wait while the user does this.
pause
c_info = getCursorInfo(dcm_obj);
if numberofselections==1, newStat = [c_info.Position(1), c_info.Position(2)].'; else newStat = [newStat [c_info.Position(1), c_info.Position(2)].']; end
%Make selected line wider
set(c_info.Target,'LineWidth',2)
numberofselections = numberofselections + 1 ;
pause
disp('either click button to stop or just hit enter')
end
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 4 Aug. 2014
I haven't been able to do it with a pushbutton. I've only been able to do it with a checkbox. You can check the checkbox state in the loop. But having a push button set some flag and then checking it in the loop does not seem to work, at least the way I tried it.
3 Kommentare
Image Analyst
am 4 Aug. 2014
Before the loop
set(handles.chkFinishNow, 'Visible', 'on');
set(handles.chkFinishNow, 'Value', 'off');
Then start your loop and check at the bottom
for or while loop....
% Check if the "Finish Now" checkbox is checked. Bail out if it is.
chkFinishNow = get(handles.chkFinishNow, 'Value');
if chkFinishNow
break;
end
end % of the loop over images.
After the loop
% Make the "Finish Now" checkbox invisible and unchecked.
set(handles.chkFinishNow, 'Value', 0, 'Visible', 'off');
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!