This repository documents best practices for building MATLAB® toolboxes. The AGENTS.md file outlines a set of actionable instructions for a Codex‑powered agent responsible for generating and maintaining a toolbox that conforms to these practices. The goal is to ensure that any automatically generated toolbox is easy for users to install, understand, and contribute to, and that it follows MathWorks’ guidelines for structure, packaging, testing, and release.
-
Choose a valid root name – Shorten the English name of your toolbox, drop the word “toolbox”, start the name with a letter and use only letters, numbers, or underscores.
Example: “QuickerSim CFD Toolbox for MATLAB” →quickerSimCFD. -
Create a README.md – Include a user‑focused
README.mdsummarizing what the toolbox does and providing installation instructions. Direct users to aGettingStarted.mlxfile for detailed usage, and include sections for contributors. -
Add a license.txt – Include a license file describing how others may use and modify your code. Without this, potential users may be unsure if they can legally use or change the toolbox.
-
Store images in an
images/folder – Keep any screenshots or badges used inREADME.mdin animages/sub‑folder to reduce clutter in the root folder. -
Prepare for additional configuration files – Place git configuration files (like
.gitignoreor.gitattributes) in the root. Build utilities (e.g.,buildfile.m) live in abuildUtilitiesfolder.
-
Toolbox folder – The
toolbox/folder contains all files that will be distributed to end‑users.-
Small toolboxes (<20 functions or classes) – Place user‑visible functions and classes directly in
toolbox/. Put internal helpers in aprivate/sub‑folder. -
Larger toolboxes – Keep common functions at the top level, group specialized functionality into sub‑folders, and consider namespaces (package folders). Implementation details go into a
<toolboxname>.internalnamespace. -
Documentation and examples – Include
doc/GettingStarted.mlxand MATLAB live script examples in anexamples/folder. -
Private functions – Keep non‑public API functions in a
private/folder. -
Applications and namespaces – Place
.mlappfiles in anapps/folder and use package folders (e.g.,+describe) to group related functions.
-
-
Argument validation and tab completion – Use MATLAB’s
argumentsblock to define input types and sizes. CreatefunctionSignatures.jsonfor enhanced tab completion. -
Namespaces – Use
+packageNamefolders to prevent name collisions and group related functions logically. -
MATLAB apps – Provide
.mlappfiles in anapps/folder and ensure they are included in packaging. -
MEX functions – For performance‑critical sections, use compiled MEX files. Follow the
MEX.mdguidelines (see section 6).
-
Use the .mltbx format – Package your toolbox into a
.mltbxfile so users can install it easily. -
Project files for packaging – From MATLAB R2025a, use the Package Toolbox task within MATLAB Projects; name the
.prjfile after the root folder. -
Icon and release folder – Store the toolbox icon in
images/and place generated.mltbxfiles in arelease/folder (do not commit it). -
Include everything under toolbox/ – Ensure all relevant content is included in the packaging dialog.
-
Naming and versioning – Use readable toolbox names and semantic versioning.
-
Release channels – Release via GitHub, MATLAB File Exchange, or shared locations.
-
Tests – Write unit tests in a
tests/folder using the MATLAB testing framework. Configure GitHub Actions to run them automatically. -
MATLAB projects – Create a
.prjfile matching the root folder name and commit it to source control. -
Source control hygiene – Include
.gitignoreand.gitattributes, and exclude derived files. -
Badges – Add “Open in MATLAB Online” and “File Exchange” badges in your README.
-
Project organisation – Place all C/C++ source files in
cpp/. Each MEX function should be in its own sub‑folder (e.g.,cpp/invertMex). -
Derived binaries – Compile MEX files to
toolbox/derived/and keep this on the MATLAB path. -
Access through MATLAB functions – Wrap MEX calls with MATLAB functions that perform input validation.
-
Platform‑specific considerations – Use
mexextto determine the correct binary extension and organize by platform. -
Out‑of‑process execution – For C++ MEX, use
mexhostfor isolation and reliability. -
Automation with buildtool – Define a
buildfile.musingMexTaskto automatically compile MEX functions. -
File exchange restrictions – Do not publish compiled MEX binaries on File Exchange; share only source code.
Include a SECURITY.md with instructions for vulnerability reporting (e.g., contact [email protected] and link to MathWorks’ disclosure policy).
When generating or updating a MATLAB toolbox, the Codex agent should:
- Set up the repository with
README.md,license.txt,images/,.gitignore, and build utilities. - Populate
toolbox/with public APIs, apps, examples, and docs; hide implementation details inprivate/. - Add validation, tab completion, apps, and MEX integration when needed.
- Write unit tests in
tests/and configure CI workflows. - Create a MATLAB project (
.prj) and compile a.mltbxfor release. - Tag and release on GitHub with semantic versioning; optionally link to File Exchange.
- Follow MEX integration guidelines and exclude binaries from version control.
- Provide
SECURITY.mdand badges for MATLAB Online and File Exchange.
By following these instructions, the Codex agent will produce MATLAB toolboxes that are well‑structured, user‑friendly, and ready for distribution.