Usage Guide
March 25, 2026 · View on GitHub
How to use MATLAB Slash Commands in your development process.
Getting Started
Basic Command Usage
All commands start with /matlab- followed by the command name:
/matlab-test
/matlab-optimize
/matlab-readme
Command Parameters
Some commands accept parameters:
/matlab-docs functionName
/matlab-test calculateMetrics
/matlab-livescript "Signal Processing"
Working with Selected Code
Many commands operate on selected code in your editor:
- Select the code you want to process
- Run the command (e.g.,
/matlab-optimize) - The command analyzes and processes the selected code
Workflow Examples
1. Starting a New Project
% Step 1: Define requirements
/matlab-refine "Create image processing pipeline for medical images"
% Step 2: Generate project structure and README
/matlab-readme
% Step 3: Create main function with documentation
/matlab-docs processMedialImages
2. Test-Driven Development (TDD)
% Step 1: Define function requirements
/matlab-refine "Statistical analysis function for time series"
% Step 2: Generate tests before implementation
/matlab-test analyzeTimeSeries
/matlab-property-test analyzeTimeSeries
% Step 3: Implement function to pass tests
function results = analyzeTimeSeries(data, options)
% Implementation here
end
% Step 4: Run tests to verify
3. Optimizing Existing Code
% Step 1: Select the code to optimize
% (Select your function in the editor)
% Step 2: Apply optimizations
/matlab-optimize
% Step 3: Add error handling
/matlab-errors
% Step 4: Verify with tests
/matlab-test
4. Documentation Pipeline
% Step 1: Document individual functions
/matlab-docs myFunction1
/matlab-docs myFunction2
% Step 2: Create Live Script tutorials
/matlab-livescript "Getting Started Tutorial"
% Step 3: Generate project README
/matlab-readme
Command Categories
Documentation Commands
Create project and function documentation:
/matlab-readme: Complete project documentation/matlab-docs: Function-level documentation/matlab-livescript: Interactive tutorials
Best Practice: Document as you code, not after.
Testing Commands
Verify code reliability:
/matlab-test: Unit tests with coverage/matlab-property-test: Mathematical property verification
Best Practice: Write tests before or immediately after implementation.
Quality Commands
Improve code performance and correctness:
/matlab-optimize: Performance enhancements/matlab-errors: Error handling and input validation
Best Practice: Optimize after functionality is complete and tested.
Development Commands
Analyze and refine code:
/matlab-explain: Understand complex algorithms/matlab-refine: Clarify vague requirements
Best Practice: Use early in development to clarify goals.
Advanced Usage
MCP-Powered Workflows
When the MATLAB MCP Core Server is connected, commands gain live capabilities:
% Run Code Analyzer, get real diagnostics
/matlab-check myFunction.m
% Generate tests AND run them immediately
/matlab-test myFunction
/matlab-run-tests
% Optimize with actual benchmarks
/matlab-optimize
% Output includes real before/after timing via MCP
% Check environment
/matlab-toolboxes
Using Commands Across Agents
These commands are available in multiple formats:
- Claude Code: Full plugin with all 13 commands
- GitHub Copilot: 6 key commands as
.prompt.mdfiles - Cursor IDE: MATLAB rules for always-on context
- Any MCP agent: Live execution via MATLAB MCP Core Server
See Cross-Agent Support for details.
Chaining Commands
Commands can be used in sequence for comprehensive development:
% Complete development pipeline
/matlab-refine "initial idea"
↓
/matlab-test functionName
↓
(implement function)
↓
/matlab-optimize
↓
/matlab-errors
↓
/matlab-docs functionName
↓
/matlab-readme
Customizing Output
Commands generate customizable output. After generation:
- Review the generated code
- Modify as needed for your specific requirements
- Integrate with your existing codebase
Integration with MATLAB Tools
Generated code works with MATLAB's built-in tools:
% Run generated tests
results = runtests('FunctionNameTest.m');
% Check code quality
checkcode('optimizedFunction.m');
% Generate documentation
publish('functionName.m', 'html');
Tips and Tricks
1. Effective Refinement
When using /matlab-refine:
- Start with high-level description
- Include constraints and requirements
- Specify performance needs
- Mention available toolboxes
2. Comprehensive Testing
For thorough testing:
% Generate both types of tests
/matlab-test myFunction
/matlab-property-test myFunction
3. Optimization Strategy
Before optimizing:
- Profile your code first
- Identify bottlenecks
- Apply
/matlab-optimizeto hot spots - Measure improvements
4. Documentation Maintenance
Keep documentation current:
- Update docs when function signature changes
- Regenerate README for new features
- Create Live Scripts for complex workflows
Common Patterns
Pattern 1: Feature Development
/matlab-refine → implement → /matlab-test → /matlab-docs
Pattern 2: Code Review
/matlab-explain → /matlab-optimize → /matlab-errors
Pattern 3: Legacy Code
/matlab-explain → /matlab-test → refactor → /matlab-docs
Pattern 4: Research Code
/matlab-property-test → /matlab-livescript → /matlab-readme
Troubleshooting
Command Not Working
- Check command syntax
- Verify code selection (if required)
- Check for required parameters
- Review error messages
Generated Code Issues
- Review MATLAB version compatibility
- Check required toolboxes
- Verify input assumptions
- Adjust parameters and regenerate
Performance Concerns
- For large codebases, process in sections
- Use specific function names rather than wildcards
- Consider breaking complex functions into smaller units
Best Practices Summary
- Start with requirements: Use
/matlab-refinefirst - Test early and often: Generate tests before/during development
- Optimize when stable: Don't optimize prematurely
- Document continuously: Keep docs in sync with code
- Iterate as needed: Commands can be run multiple times
Quick Reference Card
| Task | Command | When to Use |
|---|---|---|
| Clarify requirements | /matlab-refine | Project start |
| Generate tests | /matlab-test | Before/after implementation |
| Optimize speed | /matlab-optimize | After functionality complete |
| Add error handling | /matlab-errors | Before production |
| Document function | /matlab-docs | After implementation |
| Create tutorial | /matlab-livescript | For teaching/sharing |
| Document project | /matlab-readme | Project milestones |
| Understand code | /matlab-explain | Working with unknown code |
| Run Code Analyzer | /matlab-check | After implementation |
| Execute code | /matlab-run | Testing/debugging |
| Run test suite | /matlab-run-tests | After writing tests |
| Check toolboxes | /matlab-toolboxes | Project start |
Next Steps
- Review Command Reference for detailed command options
- Check Examples for complete workflows
- See Contributing to add custom commands