View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Automatic template for new functions

5.0 | 3 ratings Rate this file 16 Downloads (last 30 days) File Size: 3.57 KB File ID: #27132 Version: 1.0

Automatic template for new functions


Jonas (view profile)


newFunction creates an empty function with custom header

| Watch this File

File Information

If you're tired of re-typing or re-copying the same header structure over and over, newFunction may be what you're looking for.

In the command window, call
newFunction myNewFunctionName

First, newFunction checks for whether there already exists another function with the same name.

Second, an input dialog appears that requires you to enter a H1-line (one sentence description), and a synopsis (make sure you type the function name in the correct case! You can also already list explanations for input and output argument, and you can choose whether it'll be a function or a class.

Third, newFunction asks for the save directory for the function.

Fourth, newFunction creates the new function (or classdef) file with a header that includes the synopsis, the description of inputs and outputs (if provided), the Matlab version, the date and the name of the user who created the function.

Finally, newFunction opens the file in the editor and you're ready to go.


This file inspired Generate A New Function M File, With Documentation, New File, and Newfunc | Create A New Matlab Function Using A Customizable Template.

MATLAB release MATLAB 7.10 (R2010a)
Other requirements Should work as far back as R14 (or even earlier)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
30 Apr 2013 Alexis

Alexis (view profile)

Nice.It's usefull to not loose time

03 Apr 2010 John D'Errico

John D'Errico (view profile)

03 Apr 2010 Jonas

Jonas (view profile)

@John: The reason I like the dialog box is that it guarantees that there will be a H1-line, and that it allows me to switch between function, handle/value class without requiring additional inputs.

Also, if I have to type the input description anyway, why not do it so that I don't need to worry about tabs all the time?

Of course, as you said, everybody is different. You want to start writing your function right away without being bothered by a dialog window. I find that the dialog window helps me to stop and think before I start coding.

Comment only
02 Apr 2010 John D'Errico

John D'Errico (view profile)

I'll admit it is an interesting idea. Personally, what I liked about the idea is that it should create a file filled with a template that perfectly fits my own documentation style.

What I'm not excited about is that it puts up a dialog box, forcing me to fill in various pieces of information before I get to edit the function. If I will need to type in that information anyway, then why do I want to go through an extra window to start editing? This seems to me to be just extra mouse clicks, and extra typing to get what I want.

Of course, everybody is different. I'd probably rate this a 4.5. It has good help. I do like it in all other respects.

So my solution will be to write my own version of something like this, but simpler, and tailored to my specific, personal help style.

To be honest, I think the MATLAB editor should allow you to specify a default template for empty function files. Best would be to have a different template for new function, new script, new classdef files.

Contact us