binary_pattern = zeros(100,1);
binary_pattern(1:25) = 1;
binary_pattern(50:75) = 1;
binary_pattern(90:100) = 1; % to create binary pattern
minutes = [1:100]'; % scale of minutes
result = zeros(100,1);
result(1,1) = 15; % initial condition of a state
DeS = 0;
for i = 1:100
if binary_pattern(i) == 1
result(i+1) = result(i) + 1;
if DeS == -1
result(i+1) = result(i) - 1;
end
if result(i+1)>20
result(i+1)= result(i) - 1;
DeS = -1;
end
if result(i+1)<15
result(i+1) = result(i) + 1;
DeS = 0;
end
else % pattern is 0
result(i+1) = result(i) - 0.75;
end
end
result(end,:) = [];
plot(minutes,result)