Skip to content

About

Template for seeding a MATLAB toolbox repository

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

Matlab toolbox template

Use this template to create a best-practice MATLAB toolbox, ready for continuous integration with testing, code analysis, and toolbox packaging.

Step-by-step instructions

  1. Click Use this template. Fill out the fields and create a new repository

In the new repository:

  1. Go to Settings → Actions → General → Workflow permissions and select this option: "Read and write permissions"
  2. Edit the configuration file (config.yaml) to initialize your MATLAB toolbox repository.
  3. Commit and push the changes to the main branch
  4. Wait ~30 seconds for the repository to self-initialize and refresh the page
  5. 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

Create a toolbox with a coding agent

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 user

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

Configuration reference

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.

Example configuration

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: null

Directory structure and toolbox best practices

The 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_name is used instead of toolbox for 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.
    • src is widely used and familiar to many developers.
    • The additional subfolder named namespace_name supports the inclusion of a Contents.m file, enabling the use of help namespace_name to display detailed help for the package.
  • tools is used instead of buildUtilities as 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 tools folder.

Adding requirements

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)

How it works

  • Checks write permissions to ensure the workflow can proceed
  • Archives the current repository state to the template-archive branch
  • Generates the main MATLAB toolbox project from main_template → pushes to main branch

Generated branches

  • main: Complete skeleton for a MATLAB toolbox project generated from your configuration
  • gh-badges: Created by the release workflow at the first release, to store "tested with" badges
  • template-archive: Backup of the original template repository

Template Structure

The toolbox is generated from the cookiecutter template in cookiecutter_templates/main_template/.

Workflow Details

The GitHub Actions workflow consists of two jobs:

  1. check_write_permissions: Validates that the workflow has the necessary permissions to write to the repository
  2. initialize: Performs the actual template generation and branch updates

The workflow is designed to be safe and reliable:

  • Uses the existing reusable-check-push-permission.yml workflow for permission validation
  • Archives the current state before making any changes
  • Handles branch creation and updates gracefully
  • Provides detailed logging and error handling

Customizing Templates

To modify the generated projects:

  1. Edit files in cookiecutter_templates/main_template/ for the main toolbox structure
  2. Use {{cookiecutter.variable_name}} syntax to reference configuration values
  3. Test changes with the Test template workflow, which generates a toolbox from config.yaml and from the configs in .github/test-configs/, then checks, tests and packages it. It runs on pull requests and on pushes to main

Troubleshooting

Common Issues

  1. Permission errors: Ensure the repository has Actions write permissions enabled
  2. Workflow not triggering: Ensure you're pushing changes to config.yaml on the main branch
  3. Template errors: Verify that cookiecutter_templates/main_template/ exists and contains cookiecutter.json.j2 and the {{cookiecutter.repo_name}} folder
  4. Configuration errors: The initialize workflow checks config.yaml before 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 (" & : * ? < > |)

Debugging

  • Check the GitHub Actions logs for detailed error messages
  • Verify your config.yaml syntax using a YAML validator
  • Ensure all required fields in matlab_toolbox section are provided
  • Verify that the reusable-check-push-permission.yml workflow exists and is accessible

Contributing

To contribute improvements:

  1. Fork this repository
  2. Make changes to templates in cookiecutter_templates/
  3. Submit a pull request with your changes. The Test template workflow generates and tests a toolbox from them

License

This template system is provided under the MIT License. Generated projects will use the license specified in your config.yaml configuration.

About

Template for seeding a MATLAB toolbox repository

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages