Automatic generation of function comment header

조회 수: 22 (최근 30일)
Adrien Leygue
Adrien Leygue 2025년 11월 24일 13:15
편집: dpb 2025년 11월 24일 17:30
Hello,
I have a large amount of poorly documented Matlab functions (including some classes) for which I would like to create a basic header of comments (displayed when calling help). Is there a way analyze the function m-file (function definition and arguments section) and generate a m-file header based on some template?
For a m-file starting with:
function [output1,output2] = function_name(input1,input2,input3)
It would be automatically transformed to :
(This is just an exemple taken from M-file Header Template)
function [output1,output2] = function_name(input1,input2,input3)
%FUNCTION_NAME - One line description of what the function or script performs (H1 line)
%Optional file header info (to give more details about the function than in the H1 line)
%Optional file header info (to give more details about the function than in the H1 line)
%Optional file header info (to give more details about the function than in the H1 line)
%
% Syntax: [output1,output2] = function_name(input1,input2,input3)
%
% Inputs:
% input1 - Description
% input2 - Description
% input3 - Description
%
% Outputs:
% output1 - Description
% output2 - Description
%
% Example:
% Line 1 of example
% Line 2 of example
% Line 3 of example
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: OTHER_FUNCTION_NAME1, OTHER_FUNCTION_NAME2
% Author: FirstName FamilyName
% Work address
% email:
% Website: http://www.
% May 2004; Last revision: 12-May-2004
I imagine the info is there somewhere since the Matlab editor is able to provide hints when writing the call to functions.
Is there something similar for classes and their methods?
I have seen the matlab.metadata tools but it is quite low level and I have not managed to retreive the content of the arguments section.
Any help is appreciated.
Thanks a lot.
Adrien.
  댓글 수: 1
dpb
dpb 2025년 11월 24일 15:11
편집: dpb 2025년 11월 24일 17:30
I don't know anything about internals; I've always presumed it just scans the function definition line to retrieve the arguments.
"...the info is there somewhere since the Matlab editor is able to provide hints"
I hadn't really thought too much about it, but experiment to refresh memory indicates that somewhere, somehow, the editor tips are indeed processed for display and are more than just the H1 help and the argument list.
It appears for builtin and supplied m-file functions there has to be a database somewhere, but for user-written function the behavior is what I was recalling, simply the list of arguments...it will then open the H1 information supplied in the help browswer window if use the ? link, but doesn't know anything about parsing those for var type or such additional info as for the Mathworks-supplied.
Besides the FEX submission you linked in, I'd suggest looking at <https://www.mathworks.com/matlabcentral/fileexchange/107879-comment-template-for-matlab>

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

제품


릴리스

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by