MATLAB Function Reference Previous page   Next Page
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, which feval(g), when g=inline('sin(x)'), indicates that inline/feval.m would be invoked. which toLowerCase(s), when s=java.lang.String('my Java string'), indicates that the toLowerCase method in class java.lang.String would be invoked.

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 workspace variables, s is the string 'variable'. 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 statement below 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:

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, mfilename, path, type, what, who


Previous page  whatsnew while Next page

© 1994-2005 The MathWorks, Inc.