How to get Claude to write idiomatic MATLAB, not MATLAB-flavored Python
何时使用: Any MATLAB authoring task — from scripts to toolboxes.
前置条件
- MATLAB R2023b+ recommended — mathworks.com/products/matlab.html
- Skill cloned — git clone https://github.com/matlab/skills ~/.claude/skills/skills
步骤
-
Describe the taskWrite a function that computes the moving-window correlation of two time series — MATLAB, idiomatic.✓ 已复制→ Vectorized implementation, correct function signature, docstring
-
Ask for testsAdd MATLAB unit tests using matlab.unittest.✓ 已复制→ Tests in a separate file following MATLAB Test conventions
-
ProfileIf this is called in a tight loop, how would you profile and speed it up?✓ 已复制→ tic/toc or profile() suggestions, preallocation hints
结果: Idiomatic, fast, tested MATLAB code.
注意事项
- Claude reaches for Python-style loops — Explicitly ask for vectorized form; reference MATLAB docs style