2.0

2.0 | 1 rating Rate this file 4 Downloads (last 30 days) File Size: 3.42 KB File ID: #29770

Cleans Matlab syntax

by Kevin J. Delaney

 

17 Dec 2010 (Updated 15 Apr 2011)

Matlab routine (and associated Perl code) which cleans up syntax in Matlab code.

| Watch this File

File Information
Description

Matlab-invoked Perl code which cleans up syntax in Matlab code you may have downloaded or inherited:

 1) gets rid of trailing commas in "switch", "case", "if and "else" statements.

 2) uncrowds mathematical operators and variable names by adding spaces

 3) deletes trailing semicolons in "return", "end" and "function" statements.

 4) automatically indents code.

Example: clean_Matlab_syntax('C:\Matlab Code\Project\old_m_file.m')

In this example, the code creates a new file named "old_m_file_cleaned.m" in same directory as the target file.

MATLAB release MATLAB 7.11 (2010b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
26 Jan 2011 Alexandre Gramfort

- the code do not take into account "for" and "elseif"

- the code will break if you have something like

fprintf(fid, "%d foo bar", 1) % writing stuff to file

- a line like this:
%
or
    %
should not be blanked.

15 Apr 2011 Kevin J. Delaney

You're right--I've attempted to fix these shortcomings in the latest version. Thanks for your comments & please try it again.

Please login to add a comment or rating.
Updates
20 Dec 2010

Added automatic indentation.
Wrapped Perl code into Matlab function which can be called either on a single .m file or on a whole directory. Allows user to replace existing files.

15 Apr 2011

1) When separating statements & comments, now ignores "%" symbols within quoted strings.
2) More sophisticated indenting scheme.

Tag Activity for this File
Tag Applied By Date/Time
syntax Kevin J. Delaney 20 Dec 2010 14:14:40
perl Kevin J. Delaney 20 Dec 2010 14:14:40
clean Kevin J. Delaney 20 Dec 2010 14:14:40
cleanup Kevin J. Delaney 20 Dec 2010 14:14:40
code Kevin J. Delaney 20 Dec 2010 14:14:40

Contact us at files@mathworks.com