The MATLAB Editor is similar to other editor’s in that it’s a great tool with which to develop software. Additionally, though, the MATLAB Editor can be used as an investigative and exploratory tool, a publishing tool, and a demonstration tool. The feature that makes all this possible is Cell Mode.
Cell mode allows you to mark up your M-file with cell dividers (%% is the cell divider token). Each cell represents a logical block of code that can be run relatively independently of the rest of the code. I say relatively because a cell may use variables in the workspace including those defined in a previous cell.
Here’s what a file using cell mode looks like (the file below is [matlab root]/toolbox/matlab/demos/imagedemo.m – you can view at example of a similar file’s published output here):
The MATLAB Editor’s cell mode is a great tool for investigation and data exploration, as well as MATLAB publishing (I’ll cover these two topics in later entries), but I find it most valuable for giving great demos. Cell mode lets you have MATLAB running, with the code your going to demonstrate up on the screen. You can easily describe what a given cell does, as it is right up in front of your audience and it’s shown in context with surrounding code. Then with a simple keystroke (⌘⇧⏎ on Mac and Ctrl-Shift-Enter on Windows) you can evaluate that cell. I find that showing and explaining the code before displaying its output helps viewers understand what they are seeing. Cell mode provides a very natural flow between cause and effect. We use cell mode here at The Mathworks for all our MATLAB demos.
Heres how I would demo [matlab root]/toolbox/matlab/demos/imagedemo.m:
[MATLAB Ken enters stage right]…
And there you have it! An interactive demo, which lets you step through your code as you apply transforms to your data. Cell mode lets you focus on and interact with your audience. You don’t have to type code as you go to get progressive disclosure – you need only select a cell and the MATLAB Editor will help focus your audiences attention on that cell by highlighting it. Your audience gets the benefit of seeing the actual code, and then, right before them, they can watch as it generates output.
For more info, check out the cell mode help which will have you using cells in no time!
Do you use cell mode?
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.