How to get Claude to write idiomatic MATLAB, not MATLAB-flavored Python
Wann einsetzen: Any MATLAB authoring task — from scripts to toolboxes.
Ablauf
-
Describe the taskWrite a function that computes the moving-window correlation of two time series — MATLAB, idiomatic.✓ Kopiert→ Vectorized implementation, correct function signature, docstring
-
Ask for testsAdd MATLAB unit tests using matlab.unittest.✓ Kopiert→ 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?✓ Kopiert→ tic/toc or profile() suggestions, preallocation hints
Ergebnis: Idiomatic, fast, tested MATLAB code.
Fallstricke
- Claude reaches for Python-style loops — Explicitly ask for vectorized form; reference MATLAB docs style