MATLAB Answers


Generate custom "New Script/Function" template

Is there a way to modify the default script when creating a new one from the "new" pulldown (generate script/function template)?

1 Answer

Answer by MathWorks Support Team on 25 Aug 2017
 Accepted Answer

You can accomplish this workflow using the following steps:

1. Create a script “my_template.m” that has the layout of your code

For example:

>> %   Description: 
>> %   Author: Foo
>> %   Comment: 
>> close all; clear; clc

2. Create a function "make_fun.m" that utilizes "copyfile" function to copy the template to a new m-file

>> function [] = make_fun(V)
>> copyfile('my_template.m',V)
>> edit(V)

3. From the command line, you can call "make_fun" function to create a new function/script with the name of your choice

>> make_fun('newScript.m');

This solution was originally provided in the following link:


Log in to comment.

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today