MATLAB Community

MATLAB, community & more

Sharing Figures with Friends

MATLAB Mobile has a neat feature that allows you to e-mail a saved figure snapshot as a PNG file, with just two taps! You can try it out: from a snapshot in the History tab or an individual interactive figure in the Figures tab, just tap the action button in the upper-right.

Steps to email a snapshot in MATLAB Mobile

This is a neat feature, but what if you don't have MATLAB Mobile? Wouldn't it be great if you an email a figure image right from MATLAB? Of course you can! MATLAB has a handy sendmail function that uses your email SMTP server to send an email with attachments. I've most commonly seen this function used to email the results after a long simulation or to send nightly reports, but it can also be used to send pictures.

Using sendmail's attachment functionality combined with the magical print function, in two steps we can save a figure to disk and then attach it to an outgoing email. In the following code we use the current figure gcf but any figure handle can be supplied.

print(gcf,'-dpng','-r0','figure.png')
sendmail('my.friend@example.com','Look at this cool figure','Hey man, check out what I did with MATLAB!','figure.png')

The one gotcha is that is that sendmail requires a one-time set-up of your email account. The details for setting the server and username are in the sendmail documentation.

Now that I think about it, "Figures with Friends" sounds like a good idea for my next mobile app.

|
  • print

댓글

댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.