Automatic generation of function comment header
22 次查看(过去 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 :
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
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!