diary — Log command-window text to a file.
diary records command-window stdout and stderr text to an append-only log file. It supports MATLAB function syntax and command syntax for enabling, disabling, toggling, and selecting the diary file.
Syntax
diary
diary(filename)
diary off
diary onInputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
filenameOrState | StringScalar | Yes | — | Log filename, `on`, or `off`. |
Errors
| Identifier | When | Message |
|---|---|---|
| — | More than one input argument is passed to diary. | diary: expected zero or one input argument |
| — | The diary filename/state argument is not a string scalar or character row. | diary: expected filename, 'on', or 'off' |
| — | The selected diary file cannot be opened for append through the active filesystem provider. | diary: failed to open diary file |
RunMat:diary:TooManyOutputs | One or more output arguments are requested from diary. | diary: expected no output arguments |
How diary works
diarywith no input toggles logging on or off using the current diary file. The default file isdiary.diary filenameanddiary('filename')select a file and enable logging. Existing files are appended to rather than replaced.diary onenables logging to the current file, anddiary offdisables logging.- The filename/state argument must be a string scalar, string scalar array, or character row. Empty text and nonscalar text values are rejected.
- Diary writes go through the active RunMat filesystem provider, so sandboxed and virtual filesystem hosts receive the same file operations as normal file I/O builtins.
- Command-window text captured by
evalcis not written to the diary while the capture scope is active. diaryis a side-effecting sink and does not return output arguments. Requesting an output raisesRunMat:diary:TooManyOutputs.
Does RunMat run diary on the GPU?
diary is a host-side logging builtin. It writes command-window text through the filesystem provider and is excluded from GPU execution and fusion planning.
Examples
Log command-window output to a file
diary runmat_session.log
A = magic(3);
disp(A)
diary offUse function syntax to select a diary file
diary('experiment.log')
disp('started')
diary offToggle the current diary state
diary
disp('this line is logged')
diaryUsing diary with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how diary changes the result.
Run a small diary example, explain the result, then change one input and compare the output.
FAQ
Does diary overwrite an existing file?⌄
No. RunMat opens the selected diary file in append mode, matching MATLAB diary behavior.
Does diary log text captured by evalc?⌄
No. Text captured by evalc is diverted into the returned string and is not written to the normal command stream or diary log.
Does diary log workspace variables or figure state?⌄
No. It logs command-window text only. It does not change variables, figures, or execution state beyond the diary on/off state and selected filename.
Can diary return an output value?⌄
No. Like MATLAB, diary is controlled for side effects. Assigning its result raises RunMat:diary:TooManyOutputs.
Can diary write to host-specific filesystems?⌄
Yes. It uses the active RunMat filesystem provider, so desktop, sandboxed, and embedded hosts control where the log is created.
Does GPU residency matter for diary?⌄
No. diary is a host-side file sink and does not create GPU kernels, participate in fusion, or preserve GPU residency.
Related Io functions
Repl Fs
addpath · cd · copyfile · delete · dir · exist · fileattrib · fileparts · fullfile · genpath · getenv · getpref · isenv · isfile · isfolder · ispref · ls · matlabroot · memmapfile · mkdir · movefile · open · opentoline · path · pathsep · pcode · pwd · readstruct · rehash · restoredefaultpath · rmdir · rmpath · run · savepath · setenv · setpref · system · tempdir · tempname · uigetdir · uigetfile · uiputfile · unsetenv · userpath · what · winqueryreg · xmlread · xmlwrite
Tabular
arrayDatastore · csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · fileDatastore · parquetDatastore · parquetinfo · parquetread · readcell · readmatrix · readtimetable · spreadsheetImportOptions · writecell · writematrix · writetable · writetimetable · xlsread · xlswrite
Filetext
fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite · readlines · writelines
Import
Json
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how diary is executed, line by line, in Rust.
- View the source for diary in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.