This function creates a new class/function/script following the same behaviour as the "new file" desktop short-cut, except that headers are dynamically implemented, customizable and adapted for further code documentation.
The function comes with 3 default headers corresponding to 'class', 'function' and 'script' files. Feel free to adapt these header files to your own needs. They have been implemented based on the template headers proposed by Denis Gilbert, in order to facilitate the further code documentation (using mtoc++/doxygen for example).
Even if the templates are customizable, some part are implemented dynamically during the opening of the new class/function/script, such as date of creation, file name, copyright year, etc.
Basically, I have made a compilation of different tools available on the File exchange. But I wanted a tool both simple and powerful, and, most of all, able to efficiently replace the "new file" Matlab desktop short-cut, in such a way that it remains invisible to the user. To do this, you just have to add a short-cut to your short-cut toolbar using the Shortcut Editor, with callback : "new('f')" (function), "new('s')" (script) or "new('c')" (class).
Add command to Shortcut panel :
- On the Home tab, click New, and then select Command Shortcut. Or click on the "New Shortcut" in the quick access toolbar.
- In the Shortcut Editor, choose a "Label" (such as "new function"), an Icon (such as "f") and fill the "Callback" edit text panel with the corresponding command (such as "new('f')").
- Click "Save".
That's all. Whenever you want to change the headers' format, edit the corresponding file('default_function', 'default_class' or 'default_script') and save changes.
Benjamin Pillot (2021). New m-file (dynamical/documented header) (https://www.mathworks.com/matlabcentral/fileexchange/57079-new-m-file-dynamical-documented-header), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!