File Exchange

image thumbnail

% MATLAB Comment Stripping Toolbox

version (5.32 KB) by Peter J. Acklam
A small collection of utilities for stripping MATLAB comments from strings and files.


Updated 22 Mar 2004

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

This is a small collection of utilities for stripping MATLAB comments from MATLAB code. The code may be given in strings, cell arrays of strings, or read from a file or file identifier. There is full support for stripping comments from multi-line strings, that is strings with embedded newlines, which typically appear when an entire file is read in one go.

Comments and Ratings (12)

Does not seem to work (Matlab R2016b), mlstripcommentsfile produces empty output files.

I will improve my rating once the missing feature of removing %{ ... %} multiline comments is added. Besides that it's fantastic.

how to use this?


Very effective.

Awesome, thanks :)

Ideal for matlab contests...

Oh, besides of the NOT ignored lines after "...", also grouped comments are NOT ignored:

Great functions. Only my comments after a three points were left!

hi, very nice application. But when it works perfect up to line 277 after that it don't work as it supposed to work. There there anything that i can change?? like some memory limitations?? i need to use it on a file with 17000 lines. Any suggestions please.

Scott Otterson

Useful. A bit out of date, though: With R14, I'm getting a many copies of this warning:

Warning: The 'tokenize' option for regexprep is now the default behavior. If I remove 'tokenize' it goes away.

Balaji Rangaswamy

Brett Shoelson

Excellent! This is regular expressions on steroids...makes quick work of comment stripping. Thanks, Peter.

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux