Is there a way to modify default function template

When I use the New > Function button and name the created file it generates a default function code with the appropriate name. The generated function has 2 default input variables and output variables and some useless code copying the inputs to the output. Whenever I create a function like this I have two options
  1. Remove/rename the relevant sections of the function (input, output, code inside)
  2. Delete the entire function and type it out from scratch
Both options are annoying, especially doing it every time in a larger project. Is there a way to modify this default function creation. I would like to keep the matching names but rather have something like this
function [] = AssignedName()
end

5 个评论

See https://www.mathworks.com/matlabcentral/answers/354093-generate-custom-new-script-function-template which may provide some guidance on how to do do this (I haven't tried it myself but it offers an idea or two).
Thank you for the link. I've already seen that but I'm looking for something different. I would like to modify the built in template for a new function. The linked answer creates a new text file and populates it with the desired lines.
After looking for a bit I've found this question
It seems like the question has been around since 2012 and is still not implemented...
Apparently, the idea is not one that has been deemed important enough to do something about. You can always submit an enhancement request. Surely, it does not take that much effort to select a block of text, and click on the delete key. Are you creating that many thousands of new files, that this is a serious problem? Personally, having written many thousands of m-files over the years, one would think it would drive me crazy, IF it was really an issue. Not so.
And really, the link that Geoff shows does provide a simple way to populate a new file as you like it. What about that is inadequate?
"Apparently, the idea is not one that has been deemed important enough to do something about."
Here are a few file exchange entries addressing exactly this:
I will definitely make a request. I suspect there are many others having this issue but they do nothing and live with this inadequate software. The problem is that if I want to call functions from the command line I have to create function files. This forces me that for every little script I create and test I need to create new functions. The functions come with this stupid template having unnecessary input, output variables and code inside. What is their purpose? To showcase absolute beginners how to have input and output variables? How to assign the input to the output? How to write documentation?
Let's contrast it with say Visual Studio. On creating a new class for example, we get the bare minimum. But even if someone wants a something extra there are templates.

请先登录,再进行评论。

回答(1 个)

1 个评论

Thank you for the reference. But this is not what I'm looking for. I would like to change the built in ".template" files for new functions.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

产品

版本

R2021a

提问:

2021-5-31

评论:

2021-6-1

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by