Increment variable as function of time a button is held down

조회 수: 8 (최근 30일)
Alex V
Alex V 2012년 4월 27일
Is there a way to somehow capture the amount of time that a button is held down, and use it to update, in real time, a variable? my specific interest is in using a button to spin a 3d figure. I can get it to do so, but only in increments (click,*spin n rads*,click,*spin n rads* etc).
I have looked for something like this and have been unable to find an answer.
thanks, Alex

채택된 답변

Jan
Jan 2012년 4월 27일
You can use the 'WindowsButtonUpFcn' of the figure to catch the release of the button.
  댓글 수: 1
Alex V
Alex V 2012년 4월 28일
this is precisely what i knew must exist, hadn't thought to look for it in the figure properties, thank you.
so if you wanted to do this the code would be something like:
function button_callback(blahblah)
stop = 0
i = tic;
while stop = 0
handles.t = toc(i);
handles.tsum = handles.tsum+handles.t;
disp(handles.tsum)
stop = get(handles.button,'UserData');
pause(0.1)
end
WindowsButtonUpFcn_figure1(blah)
set(handles.button,'UserData',1);
and the code would behave by displaying the incremented time every 0.1s?
this seems like a really clumsy way of doing it, im sure there's a better way, could you suggest at least a direction? much obliged for the answer to the original question at least, either way.
Cheers,
Alex

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by