{"id":45170368,"url":"https://github.com/matlab/rules","last_synced_at":"2026-02-20T08:04:14.116Z","repository":{"id":332652832,"uuid":"1087331020","full_name":"matlab/rules","owner":"matlab","description":"A collection of MATLAB coding rules and guidelines optimized for use with AI coding assistants like Cursor, Windsurf, Claude Code, and GitHub Copilot","archived":false,"fork":false,"pushed_at":"2026-01-14T20:49:23.000Z","size":23,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-15T00:54:20.219Z","etag":null,"topics":["ai-coding-rules","claude-code","cline-rules","cursor-rules","matlab","matlab-rules","windsurf-rules"],"latest_commit_sha":null,"homepage":"https://www.mathworks.com/matlabcentral/discussions/ai","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc-by-4.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matlab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-31T18:21:53.000Z","updated_at":"2026-01-14T20:49:20.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/matlab/rules","commit_stats":null,"previous_names":["matlab/rules"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/matlab/rules","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matlab%2Frules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matlab%2Frules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matlab%2Frules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matlab%2Frules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matlab","download_url":"https://codeload.github.com/matlab/rules/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matlab%2Frules/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29645170,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-20T05:21:04.652Z","status":"ssl_error","status_checked_at":"2026-02-20T05:21:04.238Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-coding-rules","claude-code","cline-rules","cursor-rules","matlab","matlab-rules","windsurf-rules"],"created_at":"2026-02-20T08:04:14.013Z","updated_at":"2026-02-20T08:04:14.109Z","avatar_url":"https://github.com/matlab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# MATLAB AI Coding Rules\n\nMATLAB coding rules and guidelines for AI coding assistants like Cursor, Windsurf, Claude Code, and GitHub Copilot.\n\n## Overview\n\nRule files for AI coding assistants to generate MATLAB code that follows coding standards.\n\n## Available Rules\n\n### [matlab-coding-standards.md](matlab-coding-standards.md)\nComprehensive MATLAB coding standards covering:\n- Naming conventions for variables, functions, classes, and properties\n- Statement and expression guidelines\n- Formatting rules and whitespace conventions\n- Function and class authoring best practices\n- Error handling patterns\n\n**Use this rule when**: Writing or reviewing any MATLAB code for standards compliance\n\n### [live-script-generation.md](live-script-generation.md)\nGuidelines for generating MATLAB Live Scripts in plain text `.m` format:\n- Plain text Live Script formatting rules\n- Section structure and documentation\n- Mathematical notation and LaTeX support\n- Visualization best practices\n- Version control compatibility\n\n**Use this rule when**: Creating MATLAB Live Scripts that need to be version-controlled or AI-generated\n\n### [matlab-performance-optimization.md](matlab-performance-optimization.md)\nPerformance optimization guidelines for MATLAB development:\n- Profiling and benchmarking techniques\n- Vectorization and implicit expansion\n- Memory management and pre-allocation\n- Parallel computing with parfor and parfeval\n- App Designer performance optimization\n- JIT compiler optimization patterns\n- File I/O performance strategies\n\n**Use this rule when**: Writing performance-critical MATLAB code, optimizing existing code, or building responsive applications\n\n## Quick Start\n\nChoose your AI coding tool and follow the appropriate setup instructions:\n\n### Cursor\n\n**Option 1: Project Rules (Recommended)**\n\n1. Create a `.cursor/rules` directory in your project\n2. Copy the rule files you want to use:\n   ```bash\n   mkdir .cursor/rules\n   cp matlab-coding-standards.md .cursor/rules/\n   cp live-script-generation.md .cursor/rules/\n   cp matlab-performance-optimization.md .cursor/rules/\n   ```\n3. Cursor will automatically load these rules for your project\n\n**Option 2: Reference with @**\n\nIn your Cursor chat, reference rules directly:\n```\n@matlab-coding-standards.md Write a function to calculate eigenvalues\n```\n\n**Option 3: Global Rules**\n\nAdd to Cursor Settings \u003e General \u003e Rules for AI:\n```\nWhen writing MATLAB code, follow the standards at @matlab-coding-standards.md\n```\n\n### Windsurf\n\n**Option 1: Workspace Rules**\n\n1. Create a `.windsurf/rules` directory in your workspace\n2. Copy the rule files:\n   ```bash\n   mkdir .windsurf/rules\n   cp matlab-coding-standards.md .windsurf/rules/\n   cp live-script-generation.md .windsurf/rules/\n   cp matlab-performance-optimization.md .windsurf/rules/\n   ```\n3. Windsurf will automatically apply these rules to your workspace\n\n**Option 2: Global Rules**\n\nAdd to your `global_rules.md`:\n```markdown\n# MATLAB Development\n\nWhen working with MATLAB code:\n1. Follow naming conventions: lowerCamelCase for functions, UpperCamelCase for classes\n2. Use arguments blocks for input validation\n3. Limit function inputs to 6 or fewer\n4. Use spaces (4 per indent), not tabs\n5. Keep lines \u003c= 120 characters\n\nFor complete standards, reference: [path/to/matlab-coding-standards.md]\n```\n\n### Claude Code\n\n**Option 1: Project CLAUDE.md (Recommended)**\n\nCreate a `CLAUDE.md` file in your project root:\n```markdown\n# MATLAB Project Rules\n\nWhen working with MATLAB code in this project, import and follow these rules:\n\n@matlab-coding-standards.md\n@live-script-generation.md\n@matlab-performance-optimization.md\n```\n\n**Option 2: Direct Reference**\n\nIn your conversation with Claude Code, use the @ symbol:\n```\nPlease review this code for standards compliance @matlab-coding-standards.md\n\n[paste your code]\n```\n\n**Option 3: User-Level Rules**\n\nAdd to `~/.claude/CLAUDE.md`:\n```markdown\n# MATLAB Development Rules\n\nWhen I'm working with MATLAB code, always:\n- Follow the standards in @matlab-coding-standards.md\n- Use lowerCamelCase for functions and UpperCamelCase for classes\n- Validate inputs using arguments blocks\n- Keep code readable with proper spacing and comments\n```\n\n### GitHub Copilot\n\n**Option 1: Repository Instructions**\n\nCreate `.github/copilot-instructions.md`:\n```markdown\n# MATLAB Coding Standards\n\nThis repository uses MATLAB. Follow these standards:\n\n## Naming Conventions\n- Functions: lowerCamelCase\n- Classes: UpperCamelCase\n- Variables: lowerCamelCase (descriptive names)\n- Name-Value arguments: UpperCamelCase\n\n## Code Style\n- Indentation: 4 spaces (no tabs)\n- Line length: \u003c= 120 characters\n- Use arguments blocks for input validation\n- Limit functions to \u003c= 6 input arguments\n- Use \" for strings (not ')\n\n## Documentation\n- H1 line immediately after function declaration\n- Include help text with syntax, inputs, outputs\n- Use %% for section dividers\n\nFor complete standards, see: matlab-coding-standards.md\n```\n\n**Option 2: Path-Scoped Instructions**\n\nCreate `.github/instructions/matlab.instructions.md`:\n```markdown\n---\napplyTo:\n  - \"**/*.m\"\n  - \"**/*.mlx\"\n---\n\n# MATLAB Code Standards\n\nWhen generating or modifying MATLAB code:\n- Follow naming: lowerCamelCase for functions, UpperCamelCase for classes\n- Use arguments blocks for validation\n- 4-space indentation, \u003c= 120 char lines\n- Include clear function documentation\n- Avoid global variables, eval, command syntax in functions\n\nSee matlab-coding-standards.md for complete guidelines.\n```\n\n## Usage Examples\n\n### Example 1: Writing a New Function\n\n**Cursor / Windsurf / Claude Code:**\n```\n@matlab-coding-standards.md Write a function that validates email addresses using regular expressions. Include input validation and proper documentation.\n```\n\n**GitHub Copilot:**\n```\n// Write a MATLAB function that validates email addresses\n// Follow the project's coding standards\n// Include arguments block for validation\n```\n\n### Example 2: Creating a Live Script\n\n**Any Tool:**\n```\n@live-script-generation.md Generate a plain text MATLAB Live Script that demonstrates linear regression with:\n- Introduction to the concept\n- Sample data generation\n- Fitting a linear model\n- Visualization with plot\n- Explanation of results\n```\n\n### Example 3: Reviewing Code\n\n**Claude Code:**\n```\nReview this MATLAB code for standards compliance @matlab-coding-standards.md\n\nfunction result = calculateAverage(data)\nx=mean(data);\nresult=x;\nend\n```\n\n**Cursor:**\n```\n@matlab-coding-standards.md Check if this code follows our standards and suggest improvements:\n\n[paste code]\n```\n\n### Example 4: Refactoring\n\n**Any Tool with access to rules:**\n```\nRefactor this MATLAB function to follow @matlab-coding-standards.md:\n- Improve variable naming\n- Add input validation with arguments block\n- Fix formatting and spacing\n- Add proper documentation\n\n[paste code]\n```\n\n### Example 5: Class Design\n\n**With Cursor/Windsurf/Claude Code:**\n```\n@matlab-coding-standards.md Design a MATLAB value class for representing a 2D point with:\n- Properties: X and Y coordinates\n- Methods: distance, midpoint, translate\n- Input validation\n- Proper documentation\n```\n\n### Example 6: Performance Optimization\n\n**Any Tool:**\n```\n@matlab-performance-optimization.md Optimize this MATLAB function that processes large datasets:\n\n[paste code]\n\nFocus on vectorization, memory pre-allocation, and avoiding common anti-patterns.\n```\n\n## Combining Multiple Rules\n\nYou can reference multiple rule files in a single prompt:\n\n**Cursor / Claude Code:**\n```\n@matlab-coding-standards.md @live-script-generation.md\n\nCreate a plain text Live Script that demonstrates object-oriented programming in MATLAB. Include a class definition and usage examples. Follow all coding standards.\n```\n\n**GitHub Copilot (.github/copilot-instructions.md):**\n```markdown\n# Combined MATLAB Rules\n\nApply all:\n1. MATLAB Coding Standards (matlab-coding-standards.md)\n2. Live Script Generation rules (live-script-generation.md)\n3. Performance Optimization (matlab-performance-optimization.md)\n\nWhen creating Live Scripts, use plain text format AND follow naming/formatting standards.\nWhen writing computational code, apply performance optimization best practices.\n```\n\n## Best Practices\n\n### Rule File Organization\n- **Keep rules modular**: Each file focuses on one aspect of MATLAB development\n- **Reference, don't copy**: Use @ references to avoid duplication\n- **Update centrally**: Maintain rules in this repo, reference them in projects\n\n### Using Rules Effectively\n- **Be specific**: Reference the exact rule file you need\n- **Combine rules**: Use multiple @ references when needed\n- **Provide context**: Include relevant code or requirements with rule references\n- **Request validation**: Ask AI to verify compliance with rules\n\n### Tool-Specific Tips\n\n**Cursor:**\n- Project rules in `.cursor/rules` are always active\n- Use @ for selective rule application\n- Global rules apply to all projects\n\n**Windsurf:**\n- Workspace rules are project-specific\n- Global rules apply everywhere\n- Use file patterns to scope rules\n\n**Claude Code:**\n- CLAUDE.md is read automatically on startup\n- @ syntax allows dynamic rule inclusion\n- Can chain multiple @ references\n\n**GitHub Copilot:**\n- Instructions are always active in the repo\n- Path-scoped rules target specific file types\n- Keep instructions concise (it gets included in every request)\n\n## Contributing\n\nTo add new rules or improve existing ones:\n\n1. Create a new `.md` file following the existing format\n2. Include a clear header describing the rule's purpose\n3. Organize rules into logical sections\n4. Add examples where helpful\n5. Update this README with usage examples\n\n## License\n\nBased on:\n- [MATLAB Coding Guidelines](https://github.com/mathworks/MATLAB-Coding-Guidelines)\n- [MATLAB Prompts](https://github.com/matlab/prompts)\n\nThis work is licensed under a [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/).\n\n## Additional Resources\n\n- [MATLAB Coding Guidelines (Full)](https://github.com/mathworks/MATLAB-Coding-Guidelines)\n- [MATLAB Documentation](https://www.mathworks.com/help/matlab/)\n\n---\n\n**Note**: Always review AI-generated code and adapt rules to your project's needs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatlab%2Frules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatlab%2Frules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatlab%2Frules/lists"}