# localfunctions

MATLAB 文件中所有局部函数的函数句柄

## 语法

``fcns = localfunctions``

## 说明

``fcns = localfunctions` 返回当前文件中所有局部函数的函数句柄元胞数组 `fcns`。您不能在命令行或匿名函数的上下文中定义局部函数，因此，当您从这些上下文中调用 `localfunctions` 时，会得到一个空元胞数组。在元胞数组中，`localfunctions` 以未定义的顺序返回函数句柄。`

## 示例

```function fh = computeEllipseVals fh = localfunctions; end function f = computeFocus(a,b) f = sqrt(a^2-b^2); end function e = computeEccentricity(a,b) f = computeFocus(a,b); e = f/a; end function ae = computeArea(a,b) ae = pi*a*b; end ```

```fh = computeEllipseVals ```
```fh = 3x1 cell array { @computeFocus} {@computeEccentricity} { @computeArea} ```

```fh{3}(3,1) ```
```ans = 9.4248 ```

```x = [1 3 5 7 9 10 8 6 4 2 0 -2]; avg = mymean(x) fh = localfunctions; med = fh{2}(x) % equivalent to med = mymedian(x,n) function a = mymean(v) n = length(v); a = sum(v)/n; end function m = mymedian(v) n = length(v); w = sort(v); if rem(n,2) == 1 m = w((n + 1)/2); else m = (w(n/2) + w(n/2 + 1))/2; end end ```

```mystats ```
```avg = 4.4167 med = 4.5000 ```

```x2 = [1 1 2 6 24 120 720 5040]; fh avg2 = fh{2}(x2) ```
```fh = 2x1 cell array { @mymean} {@mymedian} avg2 = 15 ```