{"id":2153,"date":"2008-04-14T08:05:09","date_gmt":"2008-04-14T13:05:09","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2008\/04\/14\/saving-a-matlab-graphic-or-simulink-model-to-word\/"},"modified":"2016-05-18T11:32:35","modified_gmt":"2016-05-18T15:32:35","slug":"saving-a-matlab-graphic-or-simulink-model-to-word","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2008\/04\/14\/saving-a-matlab-graphic-or-simulink-model-to-word\/","title":{"rendered":"Saving a MATLAB graphic or Simulink model to Word"},"content":{"rendered":"<div class=\"content\">\r\n\r\n<i>You may have noticed some recent changes in the format of this blog. Here\u2019s what to expect on a regular basis \u2013 two topics\r\nper week.<\/i>\r\n\r\n&nbsp;\r\n<div>\r\n<ul>\r\n\t<li><i>On Tuesdays Doug will provide MATLAB tutorials.<\/i><\/li>\r\n\t<li><i>On Fridays guest bloggers Jiro, Brett and Bob will highlight File Exchange submissions.<\/i><\/li>\r\n<\/ul>\r\n<\/div>\r\nSuresh Joel's submission <a title=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadFile.do?objectId=3149&amp;objectType=FILE (link no longer works)\">SAVE2WORD<\/a> is Brett's selection for the new Pick of the Week.\r\n\r\nI really like the idea that the File Exchange is more than the just a repository of functions. It can be thought of, in fact,\r\nas a medium for collaboration in code development. Several years ago, Mark Brown shared with the MATLAB community a very popular file (<a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadFile.do?objectId=340&amp;objectType=FILE\">SAVEPPT<\/a>) that allows you to save MATLAB figures or Simulink models to a PowerPoint document. Mark's file was <a href=\"https:\/\/blogs.mathworks.com\/pick\/2004\/10\/20\/export-to-powerpoint\/\">selected<\/a> early in this blog's history as a Pick of the Week. That file subsequently inspired two submissions, including Suresh's SAVE2WORD.\r\nWith SAVE2WORD, it's now trivially easy to embed an existing figure or model in a Microsoft Word document.\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">L = 40*membrane(1,25);\r\nsurf(L,<span style=\"color: #a020f0;\">'EdgeColor'<\/span>,<span style=\"color: #a020f0;\">'interp'<\/span>)\r\nset(gca,<span style=\"color: #a020f0;\">'visible'<\/span>,<span style=\"color: #a020f0;\">'off'<\/span>)\r\ndaspect([1,1,0.9])\r\nsave2word(<span style=\"color: #a020f0;\">'test.doc'<\/span>);<\/pre>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/save2word.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nI 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\r\nthe file that inspired it, SAVE2WORD does something that a lot of users might find useful, but that is not necessarily easy\r\nto write. (The file uses ActiveX objects to access and modify the specified Word document. Note that this implies that SAVE2WORD\r\nwill only work on Windows machines. Anyone care to write a non-ActiveX version?)\r\n\r\nOne thing I would have liked to see (enhancement request?) is support for writing multiple figures or models with a single\r\ncall to SAVE2WORD. Of course, one could easily batch process open figures or models, but it would be nice if the function\r\ndid that for us.\r\n\r\nI'll have more to say in future blogs about files that inspired, or were inspired by, other File Exchange submissions. In\r\nthe meantime, feel free to share your thoughts on the most useful File Exchange file that cites inspiration from another submission.\r\n\r\n<script>\/\/ <![CDATA[\r\nfunction grabCode_e888a0c80d0843c49278b6886985982c() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='e888a0c80d0843c49278b6886985982c ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' e888a0c80d0843c49278b6886985982c';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Brett Shoelson';\r\n        copyright = 'Copyright 2008 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('\r\n\r\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\r\n\r\n\r\n\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }\r\n\/\/ ]]><\/script>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\">\r\n<a><span style=\"font-size: x-small; font-style: italic;\">Get\r\nthe MATLAB code\r\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a>\r\n\r\nPublished with MATLAB\u00ae 7.6<\/p>\r\n\r\n<\/div>\r\n<!--\r\ne888a0c80d0843c49278b6886985982c ##### SOURCE BEGIN #####\r\n%%\r\n% _You may have noticed some recent changes in the format of this blog. Here\u00e2\u20ac\u2122s\r\n% what to expect on a regular basis \u00e2\u20ac\u201c two topics per week._\r\n%%\r\n% * _On Tuesdays Doug will provide MATLAB tutorials._\r\n% * _On Fridays guest bloggers Jiro, Brett and Bob will highlight File\r\n% Exchange submissions._\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadAuthor.do?objectId=991632&objectType=author Suresh Joel>'s submission\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadFile.do?objectId=3149&objectType=FILE SAVE2WORD> is <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadAuthor.do?objectType=author&objectId=1093599 Brett>'s selection for the new Pick of the Week.\r\n%%\r\n% I really like the idea that the File Exchange is more than the just a\r\n% repository of functions. It can be thought of, in fact, as a medium for\r\n% collaboration in code development. Several years ago, <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadAuthor.do?objectType=author&objectId=805207 Mark Brown> shared with the MATLAB community a very popular file (<https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadFile.do?objectId=340&objectType=FILE SAVEPPT>) that allows you to save MATLAB figures or Simulink models to a PowerPoint document.\r\n% Mark's file was <https:\/\/blogs.mathworks.com\/pick\/2004\/10\/20\/export-to-powerpoint\/ selected> early in this blog's history as a Pick of the Week. That file subsequently inspired two\r\n% submissions, including Suresh's SAVE2WORD. With SAVE2WORD, it's now trivially\r\n% easy embed an existing figure or model in a Microsoft Word document.\r\n\r\nL = 40*membrane(1,25);\r\nsurf(L,'EdgeColor','interp')\r\nset(gca,'visible','off')\r\ndaspect([1,1,0.9])\r\nsave2word('test.doc');\r\n\r\n%%\r\n% I like Suresh's function because I can easily see it becoming a part of my\r\n% workflow when I'm writing a paper in Word. Like the file that inspired\r\n% it, SAVE2WORD does something that a lot of users might find useful, but\r\n% that is not necessarily easy to write. (The file uses ActiveX objects to\r\n% access and modify the specified Word document. Note that this implies\r\n% that SAVE2WORD will only work on Windows machines. Anyone care to write a\r\n% non-ActiveX version?)\r\n%%\r\n% One thing I would have liked to see (enhancement request?) is support for\r\n% writing multiple figures or models with a single call to SAVE2WORD. Of\r\n% course, one could easily batch process open figures or models, but it\r\n% would be nice if the function did that for us.\r\n%%\r\n% I'll have more to say in future blogs about files that inspired, or were\r\n% inspired by, other File Exchange submissions. In the meantime, feel free\r\n% to share your thoughts on the most useful File Exchange file that cites\r\n% inspiration from another submission.\r\n##### SOURCE END ##### e888a0c80d0843c49278b6886985982c\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n\r\nYou may have noticed some recent changes in the format of this blog. Here\u2019s what to expect on a regular basis \u2013 two topics\r\nper week.\r\n\r\n&nbsp;\r\n\r\n\r\n\tOn Tuesdays Doug will provide MATLAB... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2008\/04\/14\/saving-a-matlab-graphic-or-simulink-model-to-word\/\">read more >><\/a><\/p>","protected":false},"author":34,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2153"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2153"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2153\/revisions"}],"predecessor-version":[{"id":7352,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2153\/revisions\/7352"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}