MATLAB Function Reference    
which

Locate functions and files

Graphical Interface

As an alternative to the which function, use the Current Directory browser.

Syntax

Description

which fun displays the full pathname for the argument fun. If fun is a

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 private/fun limits the search to private functions. For example, which private/orthog displays the path for orthog.m in the /private subdirectory of toolbox/matlab/elmat.

which classname/private/fun limits the search to private methods defined by the MATLAB class, classname. For example, which dfilt/private/todtf displays the path for todtf.m in the private directory of the dfilt class.

which fun1 in fun2 displays the pathname to function 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 -all displays the paths to all items on the MATLAB path with the name fun. You may use the -all qualifier with any of the above formats of the 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 -all is used with this form, the output 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:

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:

See Also

dir, doc, exist, lookfor, path, type, what, who


  whatsnew while