필터 지우기
필터 지우기

How can I control the while loop iterations using a pushbutton and selecting data using datacursormode upon each iteration?

조회 수: 4 (최근 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

채택된 답변

Image Analyst
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
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');
Eric
Eric 2014년 8월 4일
Your suggestion worked along with using the "Menu" function where when you set one option for the menu as "Select Additional Data Points" and the other "Quit" (I borrowed this from one of your other answers, so you still helped me out either way). Thanks! Here is the same thing but with the Menu function:
fig = figure z = peaks; plot(z(:,30:35))
newStat=[]; numberofselections=0
button = 1
while button == 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.
numberofselections = numberofselections + 1 ;
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)
drawnow
pause
disp('either click button to stop or just hit enter')
button = menu('What do you want to do?', 'Select Additional Data Points', 'Quit');
end

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by