Use this template to create a best-practice MATLAB toolbox, ready for continuous integration with testing, code analysis, and toolbox packaging.
- Instructions for using the template
- Agent skill for creating a toolbox repository with a coding agent
- Directory structure for initialized toolbox repository
- Adding (third-party) requirements to your toolbox
- Uses MatBox and MatBox Actions for continuous integration
- Click Use this template. Fill out the fields and create a new repository
In the new repository:
- Go to
Settings→Actions→General→Workflow permissionsand select this option: "Read and write permissions" - Edit the configuration file (
config.yaml) to initialize your MATLAB toolbox repository. - Commit and push the changes to the main branch
- Wait ~30 seconds for the repository to self-initialize and refresh the page
- Before the first release, add a deploy key with write access. The release workflow (
prepare-release.yml) checks out the repository with this key so it can push the release commit and tag, and fails without it. From a clone of the new repository:ssh-keygen -t ed25519 -N "" -C "release workflow" -f deploy_key gh repo deploy-key add deploy_key.pub --allow-write --title "Release workflow" gh secret set DEPLOY_KEY < deploy_key rm deploy_key deploy_key.pub
The new-matlab-toolbox skill in skills/new-matlab-toolbox has a coding agent create the toolbox repository for you. The agent asks for the configuration values, generates the toolbox locally with the template's generator, and creates and pushes the GitHub repository with gh. It asks for confirmation before installing Python packages and before anything is sent to GitHub. The deploy key and the Codecov token are left for you to add.
The skill needs git, gh and python3, on macOS, Linux or Windows inside WSL. On Windows outside WSL, the skill points you to the step-by-step instructions above instead.
Install the skill with the GitHub CLI:
gh skill install ehennestad/matlab-toolbox-template new-matlab-toolbox --scope userAdd --agent claude-code, --agent codex or another agent to choose which agent the skill is installed for. Without a version, gh skill install installs the skill from the latest release, and the skill generates the toolbox from that same release. To use a specific release, add it to the skill name, for example new-matlab-toolbox@v0.1.0.
The following table describes all available configuration options in config.yaml:
| Variable | Description |
|---|---|
| Repository Settings | |
repository.license |
License type for your project. Options: MIT, Apache-2.0, GPL-3.0, GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-3-Clause, BSD-2-Clause, MPL-2.0, EPL-1.0, AGPL-3.0, Unlicense. Set to null, or leave the key out, to initialize the repository without a license: no LICENSE file is created and the README has no License section. Packaging then warns that LICENSE is missing until you add one. Default in config.yaml: MIT |
| MATLAB Toolbox Settings | |
matlab_toolbox.namespace_name |
MATLAB package namespace (lowercase, no spaces, no hyphens). Used for +namespace directories and function prefixes. Example: mytoolbox |
matlab_toolbox.toolbox_name |
Display name of your toolbox. Used in documentation, packaging, and as the repository title. Example: My MATLAB Toolbox |
matlab_toolbox.author_name |
Full name of the toolbox author. Used in license files, documentation, and package metadata. Example: John Doe |
matlab_toolbox.author_email |
Email address of the author. Used in package metadata and contact information. Example: john.doe@example.com |
matlab_toolbox.author_company |
Company or organization name. Used in license files and documentation headers. Example: Acme Corporation |
matlab_toolbox.toolbox_summary |
Brief one-line description of what the toolbox does. Used in package metadata and README headers. Example: A collection of signal processing utilities |
matlab_toolbox.toolbox_description |
Detailed multi-line description of the toolbox functionality, features, and use cases. Supports YAML multi-line syntax with |. Used in documentation and package descriptions. |
matlab_toolbox.dependencies |
List of MathWorks products the toolbox requires, written as product names. Listed under requirements in the README. Not installed in CI: to install a product for tests and releases, add it to matlab_products in .github/workflows/run-tests.yml and .github/workflows/prepare-release.yml, with underscores in place of spaces (Signal_Processing_Toolbox). Default: MATLAB. Example: [MATLAB, Signal Processing Toolbox] |
| Optional Settings | |
fileexchange.fex_url |
(Optional) MATLAB File Exchange URL if your toolbox is published there. Used for badges and links. Example: https://www.mathworks.com/matlabcentral/fileexchange/12345 |
codecov.badge_token |
(Optional) Codecov badge token. Used to display code coverage badges with codecov in README. Coverage reports are uploaded only when the repository also has a CODECOV_TOKEN Actions secret holding the Codecov upload token. |
repository:
license: MIT
matlab_toolbox:
namespace_name: signaltools
toolbox_name: Signal Processing Toolbox
author_name: Jane Smith
author_email: jane.smith@university.edu
author_company: University Research Lab
toolbox_summary: Advanced signal processing and analysis tools for MATLAB
toolbox_description: |
A comprehensive collection of signal processing utilities including:
- Advanced filtering algorithms
- Spectral analysis tools
- Time-frequency analysis methods
- Signal generation and manipulation functions
Designed for researchers and engineers working with digital signal processing.
dependencies:
- MATLAB
- Signal Processing Toolbox
fileexchange:
fex_url: null
codecov:
badge_token: nullThe toolbox will have the following directory structure:
├── src/mynamespace/ # Code that is packaged into the toolbox
│ ├── +mynamespace/ # MATLAB namespace for your toolbox
│ ├── examples/ # Example scripts
│ └── Contents.m # Toolbox name and version
├── docs/ # Documentation
├── tests/ # Unit tests
├── tools/ # Development tools, not packaged
│ ├── +mynamespacetools/ # installMatBox and projectdir
│ ├── tasks/ # testToolbox, codecheckToolbox, packageToolbox
│ └── MLToolboxInfo.json # Toolbox packaging metadata
└── requirements.txt # Requirements, installed with MatBox
This template and it's directory structure is heavily inspired by the MATLAB Toolbox Best Practices. If you're looking for a thorough introduction to toolbox design, their guide is a great place to start.
In the following section, I highlight some intentional deviations from their recommendations:
src/namespace_nameis used instead oftoolboxfor the folder containing code and resources that will be shared with the user.- "Toolbox" is a very specific term, and not every MATLAB package "feels" like a toolbox.
srcis widely used and familiar to many developers.- The additional subfolder named
namespace_namesupports the inclusion of a Contents.m file, enabling the use ofhelp namespace_nameto display detailed help for the package.
toolsis used instead ofbuildUtilitiesas a general-purpose folder for developer tools—such as code analysis, toolbox packaging, and documentation generation.
This template is intended as a starting point, not a one-size-fits-all solution. No single structure will be ideal for every project. However, keep the following in mind:
- The integrated GitHub Actions workflow assumes that user-facing code and tests are stored in separate subfolders at the root of the project.
- Customizations to MatBox tasks should be placed in a
toolsfolder.
The initialised repository will have a requirements.txt file where you can add requirements for the toolbox.
requirements.txt:
# This file is used to specify the dependencies for the project.
# You can install these dependencies using MatBox:
# matbox.installRequirements(toolboxRootFolder)
#
# Example of a dependency from the File Exchange:
# fex://12345-my-awesome-toolbox/1.0.0 - with fixed version number
# fex://67890-another-toolbox - will install the latest version
#
# Example of a dependency from GitHub:
# https://github.com/some-owner/some-repo@some-branch - pinned to branch
# https://github.com/some-owner/some-repo - uses default branch
The requirements will be included in the list of dependencies when a Matlab Toolbox installer is created, and users installing from an mltbx file should get all the requirements automatically. Users or developers who clone the repository using git can use MatBox to easily install requirements:
<namespace_name>tools.installMatBox() % If MatBox is not installed
matbox.installRequirements(path/to/toolboxRootDir)- Checks write permissions to ensure the workflow can proceed
- Archives the current repository state to the
template-archivebranch - Generates the main MATLAB toolbox project from
main_template→ pushes tomainbranch
main: Complete skeleton for a MATLAB toolbox project generated from your configurationgh-badges: Created by the release workflow at the first release, to store "tested with" badgestemplate-archive: Backup of the original template repository
The toolbox is generated from the cookiecutter template in cookiecutter_templates/main_template/.
The GitHub Actions workflow consists of two jobs:
check_write_permissions: Validates that the workflow has the necessary permissions to write to the repositoryinitialize: Performs the actual template generation and branch updates
The workflow is designed to be safe and reliable:
- Uses the existing
reusable-check-push-permission.ymlworkflow for permission validation - Archives the current state before making any changes
- Handles branch creation and updates gracefully
- Provides detailed logging and error handling
To modify the generated projects:
- Edit files in
cookiecutter_templates/main_template/for the main toolbox structure - Use
{{cookiecutter.variable_name}}syntax to reference configuration values - Test changes with the Test template workflow, which generates a toolbox from
config.yamland from the configs in.github/test-configs/, then checks, tests and packages it. It runs on pull requests and on pushes tomain
- Permission errors: Ensure the repository has Actions write permissions enabled
- Workflow not triggering: Ensure you're pushing changes to
config.yamlon the main branch - Template errors: Verify that
cookiecutter_templates/main_template/exists and containscookiecutter.json.j2and the{{cookiecutter.repo_name}}folder - Configuration errors: The initialize workflow checks
config.yamlbefore generating anything and reports each problem in the workflow log: invalid YAML, an unknown license, missing fields, a namespace that is not a valid MATLAB name, or characters MATLAB does not allow in a toolbox name (" & : * ? < > |)
- Check the GitHub Actions logs for detailed error messages
- Verify your
config.yamlsyntax using a YAML validator - Ensure all required fields in
matlab_toolboxsection are provided - Verify that the
reusable-check-push-permission.ymlworkflow exists and is accessible
To contribute improvements:
- Fork this repository
- Make changes to templates in
cookiecutter_templates/ - Submit a pull request with your changes. The Test template workflow generates and tests a toolbox from them
This template system is provided under the MIT License. Generated projects will use the license specified in your config.yaml configuration.