As a customer-facing engineer at MathWorks, I distribute a lot of MATLAB example files, including files posted on the File Exchange. As a policy, we add copyright information to our MATLAB files. I spend some non-trivial amount of time opening files and adding the copyright information to all of my files just before distribution. Little did I know that Mirko had created a nice utility for helping me with the process! He took the original entry by Raymond, one of my colleagues, and made some improvements to it.
The function adds a copyright text in the following format:
% Copyright 2011 The MathWorks, Inc.
One of lesser known features of a copyright string like the one above is that when you publish a file with this comment, it adds a footnote at the bottom with the copyright information:
The function is easy to use. To add a copyright line to all MATLAB files under "C:myDemos", simply type:
or you can apply this to individual files:
The function has many other options, such as customizing the organization name and the copyright year. Mirko describes in detail the modifications to Raymond's entry, but here are some of the ones I like:
- Copyright line is added either before $Revision keyword or after a blank line. MATLAB files shipped with the product all contain revision information (edit any MATLAB function). But most of my files don't have a "$Revision" line, so I like the fact that it looks for a blank line.
- Ability to have multiple copyrights with different organizations. If the file already contains a copyright, calling the function with a different organization name appends a new copyright line. This is useful when I am updating a file written by someone else from a different organization.
- Automatic update of multi-year copyrights. If the file already contains "Copyright 2009", then calling it again with 2011 will change it to "Copyright 2009-2011".
- Support for command syntax. Command syntax is useful when appropriate, and I think it's quite appropriate here. My examples above use command syntax. Compare this with the function syntax: addcopyright('myFcn.m')
- Ability to remove copyright line. It's always nice to be able to undo the process.
- Ability to add copyright to a single file (as opposed to all files inside folders). Sometimes, I just want to update a single file within a folder, so this is quite useful for me.
Thanks Mirko for this useful entry!
Oh, and I wish everyone a great new upcoming year!
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.