File Exchange Pick of the Week

April 14th, 2008

Saving a MATLAB graphic or Simulink model to Word

You may have noticed some recent changes in the format of this blog. Here’s what to expect on a regular basis – two topics per week.

  • On Tuesdays Doug will provide MATLAB tutorials.
  • On Fridays guest bloggers Jiro, Brett and Bob will highlight File Exchange submissions.

Suresh Joel's submission SAVE2WORD is Brett's selection for the new Pick of the Week.

I really like the idea that the File Exchange is more than the just a repository of functions. It can be thought of, in fact, as a medium for collaboration in code development. Several years ago, Mark Brown shared with the MATLAB community a very popular file (SAVEPPT) that allows you to save MATLAB figures or Simulink models to a PowerPoint document. Mark's file was selected early in this blog's history as a Pick of the Week. That file subsequently inspired two submissions, including Suresh's SAVE2WORD. With SAVE2WORD, it's now trivially easy to embed an existing figure or model in a Microsoft Word document.

L = 40*membrane(1,25);
surf(L,'EdgeColor','interp')
set(gca,'visible','off')
daspect([1,1,0.9])
save2word('test.doc');

I like Suresh's function because I can easily see it becoming a part of my workflow when I'm writing a paper in Word. Like the file that inspired it, SAVE2WORD does something that a lot of users might find useful, but that is not necessarily easy to write. (The file uses ActiveX objects to access and modify the specified Word document. Note that this implies that SAVE2WORD will only work on Windows machines. Anyone care to write a non-ActiveX version?)

One thing I would have liked to see (enhancement request?) is support for writing multiple figures or models with a single call to SAVE2WORD. Of course, one could easily batch process open figures or models, but it would be nice if the function did that for us.

I'll have more to say in future blogs about files that inspired, or were inspired by, other File Exchange submissions. In the meantime, feel free to share your thoughts on the most useful File Exchange file that cites inspiration from another submission.


Get the MATLAB code

Published with MATLAB® 7.6

3 Responses to “Saving a MATLAB graphic or Simulink model to Word”

  1. Jiro replied on :

    Nice post, Brett.

    I like how I can select which figures to add and append to existing documents. This would have certainly helped me back when I was in grad school. I used to do this process manually.

    MATLAB also has a capability to publish an m-file to a MS Word document. If you want to publish your m-file in a presentable form (with figures captured), read more about it here.

  2. Brett replied on :

    Thanks, Jiro. I neglected to mention MATLAB’s publishing capabilities; thanks for correcting that oversight. In fact, you can write your entire paper in the MATLAB editor, and then, at the push of a button, generate a Word doc (or LaTex, or HTML, or PowerPoint…) that automatically reflects the structure of the text in the mfile, and that automatically includes graphics and any output you want to show. Now _that_ would have been really helpful in grad school!

  3. Andrey replied on :

    Great function! I am writing my master thesis right now and it is of great help! Thank you very much!

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


MathWorks

Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.