摘自matlab

function Add new function.
New functions may be added to MATLAB’s vocabulary if they
are expressed in terms of other existing functions. The
commands and functions that comprise the new function must
be put in a file whose name defines the name of the new
function, with a filename extension of ‘.m’. At the top of
the file must be a line that contains the syntax definition
for the new function. For example, the existence of a file
on disk called STAT.M with:

        function [mean,stdev] = stat(x)%STAT Interesting statistics.n = length(x);mean = sum(x) / n;stdev = sqrt(sum((x - mean).^2)/n);defines a new function called STAT that calculates the
mean and standard deviation of a vector. The variables
within the body of the function are all local variables.
See SCRIPT for procedures that work globally on the work-
space. A subfunction that is visible to the other functions in the
same file is created by defining a new function with the function
keyword after the body of the preceding function or subfunction.
For example, avg is a subfunction within the file STAT.M:function [mean,stdev] = stat(x)%STAT Interesting statistics.n = length(x);mean = avg(x,n);stdev = sqrt(sum((x-avg(x,n)).^2)/n);%-------------------------function mean = avg(x,n)%AVG subfunctionmean = sum(x)/n;Subfunctions are not visible outside the file where they are defined.You can terminate any function with an END statement but, in most
cases, this is optional. END statements are required only in MATLAB files
that employ one or more nested functions. Within such a file,
every function (including primary, nested, private, and subfunctions)
must be terminated with an END statement. You can terminate any
function type with END, but doing so is not required unless the
file contains a nested function.Normally functions return when the end of the function is reached.
A RETURN statement can be used to force an early return.

用法(翻译)

function用来创建一个新的函数。
如果一个新的函数在现有的matlab库中不存在,那么它将会自动添加进matlab库中。组成新函数的命令和函数必须放在一个文件中,该文件的名称定义了新函数的名称,生成一个.m的文件。文件的顶部必须有一行包含新函数的语法定义,例如,磁盘上存在一个名为STAT.M的文件,其中:
function [mean,stdev] = stat(x)
%STAT Interesting statistics.
n = length(x);
mean = sum(x) / n;
stdev = sqrt(sum((x - mean).^2)/n);

定义了一个STAT函数计算向量的均值和标准差。函数体内的变量都是局部变量。有关在工作空间上全局工作的过程,请参阅脚本。

通过在前一个函数或子函数的主体后面用function关键字定义一个新函数,可以创建对同一文件中的其他函数可见的子函数。例如,avg是文件status . m中的子函数:
function [mean,stdev] = stat(x)
%STAT Interesting statistics.
n = length(x);
mean = avg(x,n);
stdev = sqrt(sum((x-avg(x,n)).^2)/n);

   %-------------------------function mean = avg(x,n)%AVG subfunctionmean = sum(x)/n;

子函数在定义它们的文件之外是不可见的。
= = 子函数的写法和调用可以百度。百度有详解

function的用法()相关推荐

  1. C++11 std::bind std::function 高级用法

    C++11 std::bind std::function 高级用法 (c++11的新特性) 原文:https://blog.csdn.net/yangjie6898862/article/detai ...

  2. boost::function的用法(二)

    boost function是一组类和模板组合,用于包装各种函数.从功能上,它类似于函数指针,但是比函数指针的功能更强大. 使用boost function,必须包含头文件 [cpp] view pl ...

  3. boost::function的用法(一)

    boost::function的用法 本片文章主要介绍boost::function的用法. boost::function 就是一个函数的包装器(function wrapper),用来定义函数对象 ...

  4. php function函数用法,js的function函数是什么?js中function的用法

    本篇文章给大家带来的内容是关于js的function函数是什么?js中function的用法,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. Function与函数 Function是 ...

  5. Fortran moudle/subroutine/function 的用法示例

    吐槽:作为一个Fortran 语言的初学者,本人深刻体会到 fortran 对于像我这样母语是C 的编程小白的强烈不友好!几天不碰,想要实现一个小小的功能就举步维艰.所以我觉得还是要多总结,今天闲来无 ...

  6. C++for_each| bind1st | ptr_fun | std::function的用法

    c++ for_each 用法_小键233-CSDN博客 传入参数 要传入参数给global function ,需要使用 ptr_fun() 这个 function adapter 将global ...

  7. function 函数用法

    function_name () {     statement1     statement2     ....     statementn } 或者 function function_name ...

  8. js中,(function(){})()的用法解析

    (function($){...})(jQuery)  含义 经常用,今天总结一下,下文摘自某网友的总结: (function($){...})(jQuery)实际上是匿名函数,不懂得朋友可以继续往下 ...

  9. 【Boost】boost库中function的用法

    要开始使用 Boost.Function, 就要包含头文件 "boost/function.hpp", 或者某个带数字的版本,从"boost/function/funct ...

最新文章

  1. 保姆级NLP学习路线来啦!
  2. mac本机 Linux服务器anaconda安装
  3. dubbo web工程示例_dubbo实战之二:与SpringBoot集成
  4. Keepalived配置文件
  5. mybatis支持驼峰自动转换sql吗_SpringBoot整合mybatis——配置mybatis驼峰命名规则自动转换...
  6. 干干净净用java_十四步 干干净净卸载Oracle
  7. 手动生成/etc/shadow文件中的密码
  8. python open读取_读取文件—open()、read()
  9. linux下封装命令,linux系统怎么封装
  10. 微博黄V认证:微博兴趣认证指定领域怎么满足条件?
  11. 计算机打印机无法打印机驱动,win7安装打印机出现无法找到打印机驱动程序包...
  12. Web浏览器发送POST请求
  13. matlab regstat函数,MATLAB如何使用binostat函数计算二项分布的期望和方差
  14. 学习|Android使用TTS语音合成
  15. 国内IT界女神程序员!和她们一样漂亮的还有谁?
  16. 在质疑声中,81岁的丁肇中或将证实“反物质世界”的存在
  17. 【office相关】excel 中使用 switch函数
  18. 聊聊我在职场的至暗时刻!
  19. Atcoder F - Mirrored(思维+搜索)
  20. SpringCloud微服务项目的api文档聚合

热门文章

  1. windows安装Weblogic教程(图文教程超详细版)
  2. 数学:分数的加减乘除模板
  3. Winsock编程接口实验:实现ipconfig
  4. 题目:求1+2!+3!+...+20!的和
  5. 对话《深入理解Java虚拟机》作者周志明:电竞选手成为Java大神之路
  6. chatbot_Chatbot开发简介
  7. 我不知道 我知道你不知道 现在我知道了 我也知道了
  8. 【计算机网络】计算机网络
  9. 百度打不开,其它网站正常
  10. Keil的安装及使用