File Exchange

image thumbnail


version (4.02 KB) by jiro
An alarm function that displays a dialog box after a set length of time.


Updated 01 Sep 2016

View Version History

View License

ALARM Displays an alarm message after a set time.
ALARM(T, MSG) displays a message after T seconds with a text message MSG. After T seconds, the computer will start beeping and display a dialog box with an option to Snooze. The beeping will stop after one minute or when the dialog box is closed. The snooze interval is 5 minutes and up to 10 snoozes are allowed. These values can be changed by ALARM(T, MSG, PROP, VAL, ...) where PROP can be one of the two:

'SnoozeInt' : snooze interval in seconds (default: 300)
'SnoozeCount' : number of maximum snoozes (default: 10)

T can also be a string of a specific time for the alarm. The string may be any of the following formats:
If the date is specified, it is ignored. The alarm will go off at the next possible HH:MM:SS.

The dialog box is a QUESTDLG, which means that all execution will be halted until the user selects one of the buttons.

ALARM by itself will list all active alarms. It will display whether the alarm has not yet gone off (pending) or has been snoozed, the time til the next alarm, and the alarm message.

ALARM('-delete') will display the active alarms and give the option of deleting any of the alarms.

When an ALARM is initially defined, it can return the number of seconds before it will go off. Use semicolon to suppress this output.

This code uses a timer object, and it will delete itself once the alarm is turned off. Note that the timer can be deleted. When MATLAB closes, it will also be deleted and will NOT be restored at the next session. The purpose of this code is for a simple time reminder function for those long coding sessions one might have.

% alarm in 60 seconds
alarm(60, 'You can stop waiting now');

% alarm at 9 PM
alarm('9:00 PM', 'It''s 9 PM!!');

% snooze time of 3 minutes for a max of 5 snoozes
alarm(120, 'Hello!', 'SnoozeInt', 180, 'SnoozeCount', 5);

Cite As

jiro (2021). ALARM (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)

alamin foraigi


alamin foraigi

i cant run

Ehsan S. Sali

Doesn't show dialog box after 1-min of beeping !! It other words beeping 1-min and then shows the dialogue box.

wag tsio

Pramud Rawat

Very nice. Would be absolutely perfect if the alarm could be set to clock time.

MATLAB Release Compatibility
Created with R14SP2
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!