How to repeat function at an interval unless a condition is met or MatLab is closed?
7 views (last 30 days)
Show older comments
I want to set up a pre-alarm clock that will play a sine wave for one minute before my phone's alarm goes off. I have the sine wave sound taken care of. What I'm not sure how to do is make that sine wave begin at a certain time of day on certain days. What I have so far is:
if weekday(now) == x;
if hour(now) == y;
if minute(now) == z;
if second(now) < 1;
makesound(.075,741,1,192000);
end
end
end
end
The makesound function is one that I put together. The inputs are volume, frequency, length of sine wave, and sample frequency. The variables x, y, and z will be integers that depend on when the alarm should turn on. The problem I'm having is figuring out how to make MatLab run that script at the desired time. What I've been trying to find is a way to make MatLab run the script something like this so that it doesn't burn up my CPU and RAM:
every 12 hours until x - day(now) = 1,
then every 4 hours until x - day(now) = 0,
then every hour until y - hour(now) = 2,
then every 30 minutes until y - hour(now) = 1
then every 10 minutes until z - minute(now) < 11,
then every minute until z - minute(now) = 1,
then every second until second(now) = 1.
After that, I'd want the script to be run every 12 hours again until the previous conditions are met again. If anyone could give me some ideas, that'd be great.
0 Comments
Accepted Answer
Star Strider
on 22 Feb 2014
You might want to experiment with the timer class functions. I’ve not done much with them myself, but they seem to do what you want.
0 Comments
More Answers (1)
Jan
on 22 Feb 2014
This seems to be a job for the operating system. Start Matlab to the specified time by cron (unix) or schtasks (Windows). The "-r" option determines a function to be called automatically.
0 Comments
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!