How can I control the while loop iterations using a pushbutton and selecting data using datacursormode upon each iteration?
3 次查看(过去 30 天)
显示 更早的评论
**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 个评论
采纳的回答
Image Analyst
2014-8-4
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 个评论
Image Analyst
2014-8-4
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');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!