MATLAB Community

MATLAB, community & more

Wait bars and beyond: call me when you’re done

Here’s a fun fact: the File Exchange contains nearly 70 different implementations of the wait bar (or progress bar, as it’s sometimes known). Stop and consider that number for a moment. It’s staggeringly large, especially when you consider that MATLAB already has a wait bar function.

Why do you suppose so many people have taken the time and trouble to submit yet another wait bar? What message is the File Exchange trying to send us?

I can offer a few guesses. Making a wait bar is a fun little project. It’s not too hard. And there are plenty of interesting variations on the basic theme: multiple wait bars, shiny wait bars, wait bars that tell you how much longer you’ll have to wait, ASCII wait bars for the command window. Wait bars with controls. There’s even a fake wait bar (From the description: Use it to show your boss that you can’t work at the moment because systemload is 100% and the calculations will take some time!). But the most important thing is that fact that wait bars are useful. They are useful because people love to make MATLAB sweat. Long computations mean a lot of time staring at the screen wondering when the iterations are going to stop. That gives you a lot of time to think about that cool new version of waitbar.m that you’re going to submit to the File Exchange.

I’ve done my share of waiting for MATLAB, and I’m here to tell you that I have the perfect enhancement for all those wait bars. I think the best wait bar is not one that makes you stare at a slowly growing progress bar. The best wait bar is one that lets you sip a cup of coffee and work on a crossword puzzle, and then texts you when it’s done.

How might we build such a thing?

Fortunately, as the world gets more mobile, it’s getting easier to find cheap, simple services to help you stay connected. I’ll describe one here, but there are others like it. I recently learned about a web service called Pushover. Pushover is platform for sending notifications to mobile devices. It’s essentially the same as text messaging. What makes it different from texting, though, is how easy it is to send a notification. All you need to do is send an HTTP POST request to their server.

How do you send a POST request from MATLAB? MATLAB Central to the rescue! Here’s a thread from the Newsreader in which Matthew Simoneau addresses this very question. It turns out all you need is MATLAB’s built-in URLREAD function.

Putting it all together, here’s what you need to do to add mobile notifications to your wait bar with Pushover: Get the app, get an account with them, register an app (MATLAB), register your device, and then make this call from MATLAB.

% Pushover Demo

userKey    = 'xxxxxxThisIsYourUserKeyxxxxxxx';
appToken   = 'xxxxxxThisIsYourAppTokenxxxxxx';
deviceName = 'iPhone';
msgTitle   = 'Calculation complete...';
msgText    = 'Now stop drinking coffee and get back to work!';

params = { ...
  'token',   appToken, ...
  'user',    userKey, ...
  'device',  deviceName, ...
  'title',   msgTitle, ...
  'message', msgText};

s = urlread(url,'POST',params);

Easy-peasy, eh?

Now leave a comment for us. Would you use wireless notification in conjunction with MATLAB? Also: I want to hear why you think there are so darned many wait bars.

  • print
  • send email


要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。