File Exchange

image thumbnail

Automatic template for new functions

version 1.0 (3.57 KB) by

newFunction creates an empty function with custom header

7 Downloads

Updated

View License

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
or
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.

Comments and Ratings (5)

Tanguy

Tanguy (view profile)

Alexis

Alexis (view profile)

Nice.It's usefull to not loose time

John D'Errico

John D'Errico (view profile)

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.

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.

MATLAB Release
MATLAB 7.10 (R2010a)

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

» Watch video