How do I add semi-colons to lines of MATLAB code automatically in MATLAB?
14 views (last 30 days)
Show older comments
MathWorks Support Team
on 29 Jun 2010
Edited: MathWorks Support Team
on 9 May 2025
I want to add semi-colons to multiple lines of MATLAB code automatically.
Accepted Answer
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.
1 Comment
Matt J
on 3 May 2025
The link, properly URL-ed,
More Answers (1)
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.
0 Comments
See Also
Categories
Find more on Debugging and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!