File Exchange

image thumbnail


version (6.46 KB) by Mirko Hrovat
add copyright information to an m-file or group of m-files.


Updated 21 Aug 2009

View Version History

View License

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

ADDCOPYRIGHT adds or modifies the copyright info to an M-file or all M-files in a designated folder as well as subfolders.

This program was originally written by Raymond Norris and has been modified to add additional features summarized below.

The copyright line that is built up looks like the following:
The copyright info is placed directly above the Revision line(containing "$Revision") or after the first blank line that is not commented after the first commented section.

The program may be invoked in a variety of ways and options, please see the comment section for details. For example one common syntax is
which calls up a dialog box to select the directory and updates the copyright info in the selected folder and all subfolders.

The following summarizes some of the differences between the original version and this version.
1. Argument list order is changed, and number of arguments is reduced.
2. Command line syntax is supported.
3. If folder argument is empty, a dialog box selects the folder.
4. Copyright info may be added to a single file.
5. Copyright info is added either before $Revision keyword or after a blank line.
6. Number of spaces between % and Copyright are now immaterial.
7. The organization is checked and if different a new copyright line is added.
8. A Def_organization constant is added.
9. Will not attempt to add copyright info to contents.m or files that are not M-files.
10. If copyright_string is blank and update is true then copyright line is deleted.
11. The correct eol character for the OS is used to rewrite the files.
12. More file checks are performed to prevent leaving temporary files.
13. Summary output to command line has been changed to be easier to read.
14. Added features to work with range of years as specified by year1-year2.

Please send me an email if you find this program useful, find bugs, or have recommendations.

Cite As

Mirko Hrovat (2021). addcopyright (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)


I would like to have the author's name automatically added to all my codes as well. Any suggestions?

Sky Sartorius

If I want to add/update copyright info for a file that's on the path but not in the current directory, a new version of the file (with copyright info) is created in the current directory. I changed line 180 to use uigetfile instead of uigetdir, which is more useful for me and helps with the aforementioned issue.


Hi Mirko,
Very nice entry! I have a need to put copyrights to all of my MATLAB files, so this will be very handy. I noticed one problem. If I have a function with some help comments and then have MATLAB code immediately after the comments (without a blank line), it doesn't append the copyright information:

function out = testfunction(in)
%TESTFUNCTION Summary of this function goes here
% Detailed explanation goes here
out = rand(in);

I expected this to become

function out = testfunction(in)
%TESTFUNCTION Summary of this function goes here
% Detailed explanation goes here

% Copyright 2011 The MathWorks, Inc.
out = rand(in);

Also, I have a couple of suggestions. I would like the tool to keep the number of blank lines between the comments and code. For example, if I have code like this:

% This is a comment

a = rand;

then the output should be

% This is a comment

% Copyright 2011 The MathWorks, Inc.

a = rand;

Notice that there's a blank line between the copyright line and the code. This preserves the spacing that originally existed in the code.

Second, I think it the function should look for:
1. "cell divisions"
2. blank line
3. Revision line
4. code line

"cell divisions" are used in cell mode like this:

%% Title
% This is a title cell.
%% Section 1
% This is section one.

In the above case, I think the copyright info should go right after the first cell (Title cell):

%% Title
% This is a title cell.

% Copyright 2011 The MathWorks, Inc.
%% Section 1
% This is section one.

This is a great entry. Thanks for creating this (and improving on Raymond's entry)! I am planning on highlighting this for Pick of the Week.

Mirko Hrovat

Good question, and I do not have a good answer. I am not sure what are the advantages of one method over the other. If the programs and revisons have the same name, then they may be easier to find. If they have different names, some versions may be missed because the keywords may be different. Take for example "keep" and "keep(2-5)" which are 5 versions plus there are others that have different names altogether. It is a little difficult to find them all. What might be best is for Mathworks File Exchange to support a version number along with the filename.

Umberto .

I have not tried your submission, but your file has the same name of another submission (objectId=3949), which you acknowledge!! Why haven't you choose a different name?

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

Community Treasure Hunt

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

Start Hunting!