MATLAB: When I execute a MATLAB file that creates multiple plots from MATLAB Notebook, why is only the last plot returned to Word

figurelastm-bookMATLABmbooknotebookplot

I execute a MATLAB file that creates multiple plots from the MATLAB Notebook Suite, and only the last plot is returned to Microsoft Word.

Best Answer

The fact that only the last plot is returned to the MATLAB Notebook document, when creating multiple plots from the Notebook Suite, is a limitation (not a bug) in MATLAB Notebook.
When executing a MATLAB file in the Notebook Suite, all of the data that is normally dumped to the MATLAB command window is dumped to the MATLAB Notebook document. However, when creating multiple plots in a file that is executed in the MATLAB Notebook document, only the last plot is returned to the MATLAB Notebook document. This occurs because plots created in the Notebook Suite are first copied to the Windows Clipboard using the Windows Meta-File Format option and then pasted into the document. When copying and pasting with the Windows Clipboard, you are only allowed to copy and paste one object at a time (a Windows Clipboard limitation). Therefore, only the last figure is available to be pasted from the clipboard.
A workaround would be to define the PLOT in separate scripts and call each on a separate line of the notebook.