MATLAB Function Reference |

**Graphical Interface**

As an alternative to the `which`

function, use the Current Directory browser.

**Syntax**

which fun which classname/fun which

/fun which classname/**private**

/fun which fun1**private**

fun2 which fun(a,b,c,...) which file.ext which fun**in**

s = which('fun',...)**-all**

**Description**

```
which fun
```

displays the full pathname for the argument `fun`

. If `fun`

is a

- MATLAB function or Simulink model in an M, P, or MDL file on the MATLAB path, then
`which`

displays the full pathname for the corresponding file - Workspace variable or built-in function, then
`which`

displays a message identifying`fun`

as a variable or built-in function - Method in a loaded Java class, then
`which`

displays the package, class, and method name for that method

If `fun`

is an overloaded function or method, then `which`

`fun`

returns only the pathname of the first function or method found.

```
which classname/fun
```

displays the full pathname for the M-file defining the `fun`

method in MATLAB class, `classname`

. For example, `which`

`serial/fopen`

displays the path for `fopen.m`

in the MATLAB class directory, `@serial`

.

`which `

limits the search to private functions. For example,

/fun
**private**`which`

`private/orthog`

displays the path for `orthog.m`

in the `/private`

subdirectory of `toolbox/matlab/elmat`

.

`which classname/`

limits the search to private methods defined by the MATLAB class,

/fun
**private**`classname`

. For example, `which`

`dfilt/private/todtf`

displays the path for `todtf.m`

in the `private`

directory of the `dfilt`

class.

`which fun1 `

displays the pathname to function

fun2
**in**`fun1`

in the context of the M-file `fun2`

. You can use this form to determine whether a subfunction or private version of `fun1`

is called from `fun2`

, rather than a function on the path. For example, `which`

get `in`

`editpath`

tells you which `get`

function is called by `editpath.m`

.

During debugging of `fun2`

, using `which`

`fun1`

gives the same result.

```
which fun(a,b,c,...)
```

displays the path to the specified function with the given input arguments. For example, if `d`

is a database driver object, then `which`

`get(d)`

displays the path `toolbox/database/database/@driver/get.m`

.

```
which file.ext
```

displays the full pathname of the specified file if that file is in the current working directory or on the MATLAB path. Use `exist`

to check for the existence of files anywhere else.

`which fun `

displays the paths to all items on the MATLAB path with the name **-all
**`fun`

. You may use the

qualifier with any of the above formats of the **-all**`which`

function.

```
s = which('fun',...)
```

returns the results of `which`

in the string `s`

. For built-in functions or workspace variables, `s`

will be the string `built-in`

or `variable`

, respectively. You may specify an output variable in any of the above formats of the `which`

function.

If

is used with this form, the output **-all**`s`

is always a cell array of strings, even if only one string is returned.

**Examples**

The first statement below reveals that `inv`

is a built-in function. The second indicates that `pinv`

is in the `matfun`

directory of MATLAB.

To find the `fopen`

function used on MATLAB `serial`

class objects

To find the `setTitle`

method used on objects of the Java `Frame`

class, the class must first be loaded into MATLAB. The class is loaded when you create an instance of the class:

The following example uses the form, `which`

`fun(a,b,c,...)`

. The response returned from `which`

depends upon the arguments of the function `feval`

. When `fun`

is a function handle, MATLAB evaluates the function using the `feval`

built-in function:

When `fun`

is the `inline`

function, MATLAB evaluates the function using the `feval`

method of the `inline`

class:

fun = inline('abs(x)'); which feval(fun,-2.5) matlabroot\toolbox\matlab\funfun\@inline\feval.m % inline method

When you specify an output variable, `which`

returns a cell array of strings to the variable. You must use the *function* form of `which`

, enclosing all arguments in parentheses and single quotes:

s = which('private/stradd','-all'); whos s Name Size Bytes Class s 3x1 562 cell array Grand total is 146 elements using 562 bytes

**See Also**

`dir`

, `doc`

, `exist`

, `lookfor`

, `path`

, `type`

, `what`

, `who`

whatsnew | while |