Neurophysiology experiments can generate tons of data. In the initial stages of a project, you can easily become overwhelmed with the results of preliminary analyses. It’s a good idea to collect together the results of these analyses into a single document. This can make it easier to peruse the results with others in your lab, for example in a lab meeting. It can also serve as an important archival mechanism, so that 6 months from now, when your adviser asks you if you checked whether there was a relationship between the bizbaz of the neurons and their frumption, you won’t have to debug your old poorly documented code to find the answer.
Matlab can generate these progress reports automatically with the publish feature. You create a regular looking cell-mode document (documents with multiple sub-sections separated by %% signs). When clicking the publish button in the editor (at the bottom right corner in the screenshot above), or equivalently using the
publish function, Matlab runs each cell in turn, and captures both the output at the console and the results of any plotting commands. If then generates a document in the format of your choice. Here’s a snapshot of such a document (part of a V4 experiment):
This report was generated with the HTML output option, which you view in Matlab’s built-in browser or in a regular web browser. In addition to generating a webpage, is interesting because it creates separate PNG files for each figure, which you can then insert into a Powerpoint, Word document, or attach in an email. Of course you can use the generated html code for your blog in the tubes, if you’re old-school enough to have one.
For sharing with colleagues or archival, the PDF option is more interesting. Here is an example of a generated PDF (same data). LaTeX and PowerPoint generation are also available; the latter is only offered on Windows so I haven’t tried it.
The output is configurable in other ways. Clicking the arrow next to the publish report icon brings up the options (shown below), which include the output format, the location of the output, whether to include code or not, and so forth. If you choose not to include the code, then the resulting output is quite usable for a lab meeting, but it’s much less annoying to generate than by manual assembly.
By using a special comment format, Matlab will generate titles before sections and print out your comments in plain text. The format that must be used is:
%% My title % My explanation of this section of code % Further explanations
The space between the % sign and the first letter of the comment is required. You can add plain text markup, html, and even LaTeX in your comments as well.
Be aware that only the last image will be captured if you use a loop. You can force Matlab to output one image per loop iteration by inserting the
snapnow command right before end statement of a loop.
Now you don’t have any excuse for not handing in a progress report to your advisor! The potential benefits of creating it are well worth the time it takes to push the publish button.
Bonus tip: it’s better to set the Position property of your figures so that they will show up with the right aspect ratio, which also occurs when using other export methods like
exportfig. I usually adjust a figure’s size with the mouse, then type
get(gcf,'Position') at the console, then copy and paste the numbers into a
set(gcf,'Position') statement You can combine a few of these steps with this function:
function setText = copyWinPosition() pos = get(gcf,'Position'); setText = sprintf('set(gcf,''Position'',[%d %d %d %d]);\n',pos); clipboard('copy',setText); end
So now instead of typing get(gcf…) at the console, type copyWinPosition(). Then Ctrl+V in the editor will paste the correct set(gcf…), so you don’t have to select, copy, or type extra text in the editor.
One response to “Obscure Matlab features #3: progress reports with publish”
[…] Matlab offers this possibility with cell-mode publishing, but the ipython notebook is leaps and bounds above Matlab’s report generation. The notebook interface is particularly well-adapted for narrative reports, as it transparently mixes code, plots, printouts, text, Markdown, and LaTeX. […]