Ken & Mike on the MATLAB Desktop

June 8th, 2009

Using the cell mode toolbar

The MATLAB Editor is great because supports many different workflows and user styles. Even though I call myself an advanced MATLAB user, I have long since stopped being surprised when I find out about something that has been there forever and is quite blatant in the UI. There are just some things that I don’t need to use in my normal work, but may be quite useful to others. One such thing is the cell mode toolbar. If the toolbar is not already present in the editor, you can activate it from the menu: Cell -> Enable Cell Mode.

cell mode toolbar

The first two items on the toolbar are the ones I use a lot. They are evaluate current cell (Ctrl+Enter) and evaluate cell and advance to next (Ctrl+Shift+Enter). This is great for live demos, where you can put a single concept (of multiple commands) in a cell and then step through a file one cell at a time. The demo workflow also fits nicely with publishing, where each step of the demo publishes into a separate section. Just remember that evaluating a cell evaluates the enclosed commands in the base workspace, which is not necessarily the same workspace as if the file were run regularly.

The next two sections of the toolbar have a textbox surrounded by either a “+,-” or a “x,%”. It’s not obvious what to do with these. If you place the caret in the editor next to a number or select a number, then the +,-,x,% buttons will light up. Pressing them will increment/decrement or multiply/divide the selected number by the amount in the box and reevaluate the current cell. This is good for tweaking a numerical parameter, such as a coefficient, tolerance, or number of iterations/interpolations. In this example I’m tweaking the peaks input, which produces a nice visual change on each increment.

cell mode toolbar

The next two buttons %% are a little more obvious but their icons are subtly different. The first one has a plus “+” in the icon and clicking it inserts a new cell marker. It’s handy to have that for the mouse, but I find it faster to type “%%”. The second one provides you a dropdown list of the cells in your file, the same way the function dropdown provides a list of functions in the file.

And remember, you can always customize the buttons that show up on the cell mode toolbar: File -> Preferences -> Toolbars -> Editor Cell Mode.

4 Responses to “Using the cell mode toolbar”

  1. Guy replied on :

    My favorite element of the cell mode toolbar is the “-+” part. Since I discovered the possibilities of this feature, I use it everytime I need to tune or debug a Simulink model.

    By writing a simple script, I can change the value of a parameter (using the “-+ feature”), simulate the model using SIM, plot the results and see the effect. click, click, click, done. It speeds up things by 1000%.

  2. Mike replied on :

    Guy, great point. Simulink parameters are an excellent usage of this!

  3. Brett Shoelson replied on :

    Hey Ken and Mike,
    Whenever I present MATLAB in bootcamp mode (which is very often), I always highlight the utility of cell-mode editing. One of the benefits I point out is the vastly under-utilized incrementer tools–few people know what they’re for. I typically will increment an initial guess at a threshold for an image, for instance.

    But I also like to point out that one can get more creative with these buttons. For instance, if one wanted to try out our 6 different (IPT) algorithms for edge detection, the incrementer tools allow that, too:

    %%
    algs = {’Sobel’,'Prewitt’,'Roberts’,'LOG’,'Zerocross’,'Canny’};
    incr = 1; %INCREMENT HERE
    imshow(edge(tissueMask,algs{incr}))
    title([algs{incr} ‘ Edge Detection’])

    Cheers,
    Brett

  4. Mike replied on :

    Thanks for that idea, Brett from Pick of the Week. That’s a good use of the incrementer. If my example is the 0-order use, yours is the 1-order. I wonder what the next level is…

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).


Ken & Mike work on the MATLAB Desktop team.
  • Ori: The current folder shortcut used to be alt-y. Now it is alt-o. However, while in the editor window, alt-o opens...
  • Jose Miguel: Hi First of all, thanks for the post, it is really useful. I am trying to develop a Java GUI within...
  • Ken: Hi Siddharth, There isn’t currently any way to move the docking controls. Feel free to submit an...
  • Phil: I have the same problem as described above with UITable working fine in the Matlab environment but showing no...
  • Siddharth: Is there any way to move the position of the docking controls (or eliminate them through some...
  • Chris: Yes, it is a challenge to organize functions into categories, especially with so many functions. Ken and I...
  • Mike: Thanks for fielding that one, Yair.
  • Yair Altman: Jimmy - if you mean that you wish to include hyperlinks in your function’s help comment, that will...
  • OysterEngineer: Thanks for explaining the Function Browser. I fired it up and gave it a try. It appears that it has...
  • Jimmy: Is there any way to include hyperlinks in a comment, such as the standard help at the beginning of a function?

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