matlab 函数头注释规范

本文介绍了MATLAB函数头注释的规范,包括函数功能、参数介绍、示例、注意事项、版权信息和日志信息的编写要求。建议在不同部分之间空一行,二级信息可缩进。版权信息中推荐留下联系方式,但为防垃圾邮件,通常用#代替@。

matlab函数头注释分为以下几部分:

  1. 函数功能简要说明
  2. 函数参数简要介绍
  3. 举例
  4. 注意事项或建议
  5. 版权信息
  6. 日志信息

注意

  1. 在不同的注释部分之间最好能够空一行,但为了能够保证注释的连续性,仍然保持这一行为注释行。每一部分的注释,如果有二级信息,可以空两格进行缩进。
  2. 版权信息中最好能够留着邮箱,这样方便使用你的代码的人在遇到问题时跟你联系,但为了防止垃圾邮件,一般用#替换@。

例子

    常见的size函数的头注释

%SIZE   Size of array.  
%   D = SIZE(X), for M-by-N matrix X, returns the two-element row vector
%   D = [M,N] containing the number of rows and columns in the matrix.
%   For N-D arrays, SIZE(X) returns a 1-by-N vector of dimension lengths.
%   Trailing singleton dimensions are ignored.
%
%   [M,N] = SIZE(X) for matrix X, returns the number of rows and columns in
%   X as separate output variables. 
%   
%   [M1,M2,M3,...,MN] = SIZE(X) for N>1 returns the sizes of the first N 
%   dimensions of the array X.  If the number of output arguments N does
%   not equal NDIMS(X), then for:
%
%   N > NDIMS(X), SIZE returns ones in the "extra" variables, i.e., outputs
%                 NDIMS(X)+1 through N.
%   N < NDIMS(X), MN contains the product of the sizes of dimensions N
%                 through NDIMS(X).
%
%   M = SIZE(X,DIM) returns the length of the dimension specified
%   by the scalar DIM.  For example, SIZE(X,1) returns the number
%   of rows. If DIM > NDIMS(X), M will be 1.
%
%   When SIZE is applied to a Java array, the number of rows
%   returned is the length of the Java array and the number of columns
%   is always 1.  When SIZE is applied to a Java array of arrays, the
%   result describes only the top level array in the array of arrays.
%
%   Example:
%   If
%      X = rand(2,3,4);
%   then
%      d = size(X)              returns  d = [2 3 4]
%      [m1,m2,m3,m4] = size(X)  returns  m1 = 2, m2 = 3, m3 = 4, m4 = 1
%      [m,n] = size(X)          returns  m = 2, n = 12
%      m2 = size(X,2)           returns  m2 = 3
%
%   See also LENGTH, NDIMS, NUMEL.

%   Copyright 1984-2005 The MathWorks, Inc.
%   $Revision: 5.13.4.6 $  $Date: 2005/06/21 19:28:41 $
%   Built-in function.

参考:http://www.52souji.net/my-own-standards-for-comment-of-matlab-function/

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值