Get Matlab to email you when it’s done running!

This is a guest post by Kyle Kloster, one of the students I’m working with at Purdue University. Kyle has been doing some large, long running experiments on big graphs. He writes:

The random-walk transition matrices for Twitter, LiveJournal, and Friendster can take several minutes just for matlab to load. The actual experiments we carry out (computing columns of the matrix exponential) can take hours, and this week I got tired of checking in every 10 minutes to see if Matlab had finished (or crashed).

We asked around a bit on Twitter to see if anyone knew how to have Matlab email you when something finishes. Thanks to @jimfonseca for pointing us to the perfect Matlab documentation on sending email. (And also, this documentation on how to use gmail to send email in Matlab.) We used this documentation to build the matlabmail function.

MATLABMAIL( recipient, message, subject )

  sends the character string stored in 'message' with subject
  'subject' to the address in 'recipient', from the email 
  address stored in the file. This requires that the 
  sending address is a GMAIL email account.

View matlabmail.m

One troubling part is that you need to tell Matlab the password to the account that you want to use as “sender”. David suggested creating a dummy gmail account that the whole research group could use as a sender — this way we can use a randomly generated password for one shared account to spare each of us having to use personal login info.

Now having one line of code at the end of a matlab file alerts me when a trial is over!

matlabmail('XXXXXX@purdue.edu', 'twitter experiment done', ...
           'subjectline here');

It’s even possible to attach files using these commands, in case you’d like Matlab to send you a JPEG containing the results from your latest experiments.

Note that the function works for gmail accounts only, and it won’t work for gmail accounts that have “2-step verification” enabled.

This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Get Matlab to email you when it’s done running!

  1. jerrod says:

    Also, most cell carriers can receive a sms from email. So you can get txt updates of your program’s progress.

  2. Đorđe St. says:

    It will work for “2-step verification” enabled Gmail accounts, just make password for Matlab in few easy steps:

    1. Go to https://www.google.com/settings/security
    2. Open Settings under 2-Step Verification and head to App-specific passwords tab
    3. Click on Manage application-specific passwords
    4. Choose Select app or Select device -> Other (Custom name) and name it as you want and generate new password for Matlab with Generate button

    https://support.google.com/accounts/answer/185833

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s