How do I add semi-colons to lines of MATLAB code automatically in MATLAB?

14 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 9 May 2025
Edited: MathWorks Support Team on 9 May 2025
Starting in MATLAB R2021b, the MATLAB Editor as well as the Live Editor support column selection, code autocompletion and refactoring. Please refer to Edit and Format Code - MATLAB & Simulink for more details. 
For MATLAB Releases prior to R2021b there is no direct, built-in way to globally control the placement of semi-colons in MATLAB files. You will have to write custom scripts to do that. See attached function called "fixSemiColon()" which calls "readLineOfFile()" and "replaceFileLine()" and shows a way of doing this.

More Answers (1)

Matt J
Matt J on 3 May 2025
You can use favoriteForceSemicolons.m from this File Exchange download,
to add semicolons to highlighted regions of code (or select the entire document). It is easiest if you install it as a Quick Access button, as recommended in the Desciption section of the submission.
There is also a button definition favoriteStripSemicolons.m for stripping away semicolons, which can also be useful.

Categories

Find more on Debugging and Analysis in Help Center and File Exchange

Products


Release

R2010a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!