Generate custom "New Script/Function" template
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 25 de Ag. de 2017
Editada: MathWorks Support Team
el 19 de Dic. de 2019
Is there a way to modify the default script when creating a new one from the "new" pulldown (generate script/function template)?
Respuesta aceptada
MathWorks Support Team
el 19 de Dic. de 2019
Editada: MathWorks Support Team
el 19 de Dic. de 2019
1) The preferred method is the following:
You can use the API listed below to create a new document with pre-populated text:
>> matlab.desktop.editor.newDocument(text); % `text` is the character array to pre-populate upon opening up the editor
For example, if the template code in your MATLAB script is:
% New Script
clc
clear
Then the corresponding command using the given API would be:
>> matlab.desktop.editor.newDocument(['% New Script' newline 'clc' newline 'clear']);
To integrate this command in your workflow, you could create a Favorite Command (via Favorites \ New Favorite) and use it as a button on the Quick Access Toolbar. That way you could simply click the button to create a new script with the desired template code.
2) Otherwise you can use the method listed below:
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:
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!