MATLAB Answers

0

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:

https://www.mathworks.com/matlabcentral/answers/56672-how-can-i-create-a-standard-matlab-template-for-new-programs

  0 Comments

Log in to comment.


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!