Write a runnable notebook
A RunMat notebook is a Markdown file with runnable code cells. Prose, equations, diagrams, code and figures sit in one document, and the file stays plain .md, so it diffs and reviews like any other text file.
Create a notebook
- Add a file whose name ends in
.md, for examplefilter.md. Desktop opens Markdown files in the notebook editor. - Write prose as you would in any Markdown editor. Type
/at the start of a line for a menu of blocks: headings, lists, quotes, code blocks, math blocks, tables and RunMat Cell. - Choose RunMat Cell to add a runnable cell, and type MATLAB-syntax code into it.
In the file, a runnable cell is a fenced block tagged runmat:
# Low-pass filter
A first-order low-pass filter with a 250 Hz cutoff.
```runmat
fc = 250;
f = logspace(0, 4, 400);
H = 1 ./ (1 + 1i*f/fc);
```
The magnitude falls 3 dB at the cutoff.
```runmat
semilogx(f, 20*log10(abs(H)));
xlabel("Frequency (Hz)");
ylabel("Magnitude (dB)");
```A block tagged matlab stays a code listing and doesn't run. Keep reusable functions in .m files in the project and call them from cells.
Run the notebook
With the notebook open, select Run filter.md in the top bar. Desktop runs the cells from top to bottom in one shared workspace, so a cell can use variables an earlier cell created. Each cell's figures appear under it.

The bar under the notebook counts the cells that ran, the warnings and the figures, for example 2/2, 0, 1. Its Variables, Trace and Log tabs show the notebook's workspace and messages. The runtime panel shows the same variables; its figure area offers Transfer Figures Here if you want the figures beside the notebook instead of inside it.
Keep outputs current
When you change a cell after a run, its saved output may no longer match. The notebook shows Output may be out of date. Run the notebook to refresh. with a Run notebook button. Before you share a notebook, run it from the top so every output matches the code above it.
Two settings in Settings › Project (named Sandbox in the sandbox) control a full run:
| Setting | Choices |
|---|---|
| When a notebook cell fails | Stop at the failing cell, or Keep running the cells after it |
| Running a notebook again after you stop it | Run the remaining cells, or Start from the top |
Save outputs with the notebook
When you're signed in and Persist runs is on in Settings › Project, Desktop keeps each run's output, figures and variables with the project. Reopening the notebook later shows them without running it again. Large values and figure data are stored as project files beside the notebook, and the Markdown keeps a short reference to each one.
Saved output records what an earlier run produced. To confirm the current code, data and settings still produce it, run the notebook again. If others will rerun it, keep the datasets and runmat.toml it needs in the project.
Write math and diagrams
Notebooks render LaTeX math, inline as $H(f)$ and as display blocks between $$ lines, and Mermaid diagrams in a mermaid code block. Double-click an equation to edit it.
See Go back to an earlier run for how saved runs are kept and restored.
