| MATLAB Function Reference | ![]() |
As an alternative to the which function, use the Current Directory Browser.
which fun
which classname/fun
which private/fun
which classname/private/fun
which fun1 in fun2
which fun(a,b,c,...)
which file.ext
which fun -all
s = which('fun',...)
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, then which displays a message identifying fun as a variable
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 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 is being called instead of 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. To display the path for a file that has no file extension, type "which file." (the period following the filename is required). Use exist to check for the existence of files anywhere else.
which fun -all d isplays 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.
The statement below indicates that pinv is in the matfun directory of MATLAB.
which pinv matlabroot\toolbox\matlab\matfun\pinv.m
To find the fopen function used on MATLAB serial class objects
which serial/fopen matlabroot\toolbox\matlab\iofun\@serial\fopen.m % serial method
To find the setMonth method used on objects of the Java Date class, the class must first be loaded into MATLAB. The class is loaded when you create an instance of the class:
myDate = java.util.Date; which setMonth
MATLAB displays:
setMonth is a Java method % java.util.Date 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 bytesdir, doc, exist, lookfor, mfilename, path, type, what, who
![]() | whatsnew | while | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |