-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimerTest.m
More file actions
85 lines (60 loc) · 2.04 KB
/
timerTest.m
File metadata and controls
85 lines (60 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
clc, clear;
% Grab references to all existing timers
dump = timerfindall
% Delete the old timers
delete(dump)
% Duration of each sequence
SequenceDurations = [2,1,2,1,3];
j = 1;
% % Create one timer per sequence item
% for i = 1:length(SequenceDurations)
% Timers(i) = timer( ...
% 'ExecutionMode', 'singleShot', ...
% 'StartDelay', SequenceDurations(i), ...
% 'TimerFcn', 'disp(j), tic, start(Timers(j+1)), pause(SequenceDurations(j)), toc, j=j+1;');
% % Timer fires once
% % After SequenceDurations(i) seconds
% % And executes a line of code
% end
%
% disp([Timers.startdelay])
%
% % Start the cascade
% start(Timers(j))
%
% % Execute the timers sequentially
% % for j = 1:length(SequenceDurations)
% % disp('next timer')
% % start(Timers(j))
% % pause(SequenceDurations(j))
% % len = toc
% % fprintf('Timer %1.0f fired after %1.0f seconds.\n',j,len)
% % end
% Timer as a string
% TimerString = sprintf('timer(''ExecutionMode'',''SingleShot'',''StartDelay'',''%1.0f'',''TimerFcn'',''toc, sprintf(''Timer %s fired.\n'',j), j=j+1; stop(SequenceTimer), SequenceTimer.Period=SequenceDurations(j);disp(SequenceTimer.StartDelay), start(SequenceTimer); tic,',SequenceDurations(j),'%1.0f');
% TimerString = sprintf('stop(SequenceTimer), j=j+1,SequenceTimer.Period=SequenceDurations(j),SequenceTimer.StartDelay=SequenceDurations(j),start(SequenceTimer),toc')
%
% disp(TimerString)
% % Self editing timer
% SequenceTimer = timer( ...
% 'ExecutionMode', 'fixedSpacing', ...
% 'Period', SequenceDurations(j), ...
% 'TasksToExecute', inf, ...
% 'StartDelay', SequenceDurations(j), ...
% 'TimerFcn', TimerString );
%
%
% tic
% disp(SequenceDurations)
% disp(j)
% start(SequenceTimer);
% Build all timers first
for i = 1:length(SequenceDurations)
Timers(i) = timer( ...
'ExecutionMode', 'singleShot', ...
'StartDelay', SequenceDurations(i), ...
'TimerFcn', 'toc, j=j+1, tic, start(Timers(j))');
end
tic
disp(SequenceDurations)
start(Timers(j))