# Advanced MATLAB: Timer objects 41

Posted by **Doug Hull**,

**Category:**- Format: PodCast,
- Format: Video,
- Level: Advanced

## 41 CommentsOldest to Newest

**1**of 41

**2**of 41

**3**of 41

**4**of 41

**5**of 41

**6**of 41

**7**of 41

**8**of 41

**9**of 41

**10**of 41

**11**of 41

**12**of 41

**13**of 41

**14**of 41

**15**of 41

**16**of 41

**17**of 41

**18**of 41

**19**of 41

**20**of 41

function figure1_KeyPressFcn(hObject, eventdata, handles) handles.Key = get(gcf, 'CurrentKey') switch(handles.Key) case 'f12' tic; accurateTimer = timer; set(accurateTimer, 'Period', .1) set(accurateTimer, 'TimerFcn', 'handles.elapsedTime = toc;') start(accurateTimer) handles.workingTime = floor(handles.elapsedTime) %%Where I get my "Reference to Nonexistent Field Error"

**21**of 41

**22**of 41

**23**of 41

**24**of 41

[] = function test() t = timer('TimerFcn','disp(''Taking too long''); return','StartDelay',5); start(t) pauseIs there a way to set up the timer so that function test will terminate? Thanks, Ryan

**25**of 41

**26**of 41

**27**of 41

**28**of 41

**29**of 41

**30**of 41

**31**of 41

**32**of 41

function waitnow(length) t_w = timer('StartFcn', 'disp(''waiting for refresh...'')', 'TimerFcn','disp(''waited'')','StartDelay',length); start(t_w); wait(t_w); % stop(t_w);

**33**of 41

**34**of 41

**35**of 41

**36**of 41

**37**of 41

**38**of 41

**39**of 41

**40**of 41

t3 = timer('TimerFcn', @authentic_wrapper, 'Period', 10, 'ExecutionMode', 'FixedSpacing'); start(t3);First line is OK but after start function is says "??? Error while evaluating TimerFcn for timer 'timer-1' Too many input arguments." I have the .m file of the type function with the name authentic_wrapper in the same directory. What do I do wrong? Syntax seems to be right. Thank you. Paul

**41**of 41

## Recent Comments