Locate functions and files - MATLAB which (2024)

Locate functions and files

collapse all in page

Syntax

which item

which fun1 in fun2

which ___ -all

str = which(item)

str = which(fun1,'in',fun2)

str = which(___,'-all')

Description

example

which item displays the full path for item.

  • If item is a MATLAB® function in a MATLAB code file (.m,.mlx, or .p extension), or a saved Simulink® model (.slx or .mdl extension), then which displays the full path for the corresponding file. item must be on the MATLAB path.

  • If item is a method in a loaded Java® class, then which displays the namespace, class, and method name for that method.

  • If item is a workspace variable,then which displays a message identifying item asa variable.

  • If item is an unsaved Simulink model that is loaded in Simulink, then which displays a message identifying item as a new Simulink model.

  • If item is a file name includingthe extension, and it is in the current working folder or on the MATLAB path,then which displays the full path of item.

If item is an overloaded function or method,then which item returns onlythe path of the first function or method found.

example

which fun1 in fun2 displaysthe path to function fun1 that is called by file fun2.Use this syntax to determine whether a local function is being calledinstead of a function on the path. This syntax does not locate nestedfunctions.

example

which ___ -all displays the paths to all items on the MATLAB path with the requested name, as well as any files in special folders that have been implicitly added to the path. Such items include methods of instantiated classes. For more information about these special folders, see What Is the MATLAB Search Path. You can use -all with the input arguments of any of the previous syntaxes.

example

str = which(item) returnsthe full path for item to str.

example

str = which(fun1,'in',fun2) returnsthe path to function fun1 that is called by file fun2.Use this syntax to determine whether a local function is being calledinstead of a function on the path. This syntax does not locate nestedfunctions.

example

str = which(___,'-all') returnsthe results of which to str.You can use this syntax with any of the input arguments in the previoussyntax group.

Examples

collapse all

Locate MATLAB Function

Locate the pinv function.

matlabroot\toolbox\matlab\matfun\pinv.m

pinv is in the matfun folderof MATLAB.

You also can use function syntax to return the path to str.When using the function form of which, encloseall input arguments in single quotes.

str = which('pinv');

Locate Method in a Loaded Java Class

Open Live Script

Create an instance of the Java® class. This loads the class into MATLAB®.

myDate = java.util.Date;

Locate the setMonth method.

which setMonth
setMonth is a Java method % java.util.Date method

Locate Private Function

Find the orthog functionin a private folder.

which private/orthog
matlabroot\toolbox\matlab\elmat\private\orthog.m % Private to elmat

MATLAB displays the path for orthog.m inthe /private subfolder of toolbox/matlab/elmat.

Determine If Local Function Is Called

Determine which parseargs functionis called by area.m.

which parseargs in area
matlabroot\toolbox\matlab\specgraph\area.m (parseargs) % Local function of area

You also can use function syntax to return the path to str.When using the function form of which, encloseall input arguments in single quotes.

str = which('parseargs','in','area');

Locate Function Invoked with Given Input Arguments

Suppose that you have a matlab.io.MatFile object that corresponds to the example MAT-file 'topography.mat':

Display the path of the implementation of who thatis invoked when called with the input argument (matObj).

which who(matObj)
matlabroot\toolbox\matlab\iofun\+matlab\+io\MatFile.m % matlab.io.MatFile method

Store the result to the variable str.

str = which('who(matObj)')
str =matlabroot\toolbox\matlab\iofun\+matlab\+io\MatFile.m'

If you do not specify the input argument (matObj),then which returns only the path of the first functionor method found.

which who
built-in (matlabroot\toolbox\matlab\general\who)

Locate All Items with Given Name

Display the paths to all items on the MATLAB path with the name openedFiles.

which openedFiles
built-in (matlabroot\toolbox\matlab\iofun\openedFiles)

Return Path Names

Open Live Script

Return the results of which to str.

Find the orthog function in a private folder. You must use the function form of which, enclosing all arguments in parentheses and single quotes.

str = which('private/orthog','-all');whos str
 Name Size Bytes Class Attributes str 1x1 314 cell 

Input Arguments

collapse all

itemFunction or file to locate
character vector | string scalar

Function or file to locate, specified as a character vector or string scalar. When using the function form of which, enclose all item inputs in single or double quotes. item can be in one of the following forms.

Form of the item InputPath to Display
fun

Display full path for fun, which canbe a MATLAB function, Simulink model, workspace variable,method in a loaded Java class, or file name that includes thefile extension.

To display the path for a file that has no file extension, type which file. (The period following the file name is required). Use exist to check for the existence of files anywhere else.

/fun

Limit the search to functions named fun thatare on the search path. For example, which /myfunction displaysthe full path for function myfunction.m, but notbuilt-in or JAVA functions with the same name.

private/funLimit the search to private functions named fun.For example, which private/orthog or which('private/orthog') displaysthe path for orthog.m in the /private subfolderof the parent folder.

fun(a1,...,an)

Display the path to the implementation of function fun which would be invoked if called with the input arguments a1,...,an. Use this syntax to query overloaded functions. See the example, Locate Function Invoked with Given Input Arguments.

Data Types: char | string

fun1Function to locate
character vector | string scalar

Function to locate, specified as a character vector or string scalar. fun1 can be the name of a function, or it can be in the form fun(a1,...,an). For more information about the form, fun(a1,...,an), see Locate Function Invoked with Given Input Arguments.

When using the function form of which, enclose all fun1 inputs in single or double quotes, for example, which('myfun1','in','myfun2').

Data Types: char | string

fun2Calling file
character vector | string scalar

Calling file, specified as a character vector or string scalar. fun2 can be the name of a file, or it can be in the form fun(a1,...,an). For more information about the form, fun(a1,...,an), see Locate Function Invoked with Given Input Arguments.

When using the function form of which, enclose all fun2 inputs in single or double quotes, for example, which('myfun1','in','myfun2').

Data Types: char | string

Output Arguments

collapse all

str — Function or file location
character vector | cell array of character vectors

Function or file location, returned as a character vector or cell array of character vectors if you use '-all'.

  • If item is a workspace variable, then str is the character vector 'variable'.

  • If str is a cell array of character vectors, then each row of str identifies a result of which. The results are ordered according to the Function Precedence Order. If there are shadowed results, you should not rely on the order of the shadowed functions and methods in str. To determine if a result is shadowed, call which without specifying str. which indicates shadowed results by the comment % Shadowed.

Limitations

  • When the class is not loaded, which only finds methods if they are defined in separate files in an @-folder and are not in any namespaces.

Tips

  • For more information about how MATLAB uses scopeand precedence when calling a function, see Function Precedence Order.

Extended Capabilities

Version History

Introduced before R2006a

See Also

dir | doc | exist | lookfor | mfilename | path | type | what | who | fileparts

Topics

  • What Is the MATLAB Search Path?

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Locate functions and files - MATLAB which (1)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Locate functions and files - MATLAB which (2024)

FAQs

How to find the location of a function in MATLAB? ›

Find functions by browsing the list or by typing a search term. For example, search for the term fourier. In the search results, a parenthetical term after a function name indicates either that the function is in a product folder other than MATLAB®, or that there are multiple functions with the same name.

How to locate a file in MATLAB? ›

Find Files
  1. Click the search button in the Current Folder toolbar. The address bar becomes a search field.
  2. Type a portion of a file name. The asterisk character (*) is a wildcard. ...
  3. Press Enter. MATLAB® displays all files within the current folder (including its subfolders) that match that file name.

How do I find all files of a certain type in MATLAB? ›

To search for multiple files, use wildcards in the file name. For example, dir *. txt lists all files with a txt extension in the current folder.

What are functions and files in MATLAB? ›

Program files can contain multiple functions. If the file contains only function definitions, the first function is the main function, and is the function that MATLAB associates with the file name. Functions that follow the main function or are included in script code are called local functions.

How do you find the source of a function in MATLAB? ›

For most Matlab functions you can see the source code by typing "edit <function_name>" at the Matlab prompt.

How to get file location in MATLAB? ›

Check Whether File or Folder on Search Path

To determine whether a file is on the search path, run which filename . If the file is on the search path, MATLAB returns the full path to the file. To determine whether a file or folder is on the search path, use the Current Folder browser.

How do I locate a file? ›

How to Locate Files and Folders in Your Computer
  1. Choose Start→Computer. ...
  2. Double-click an item to open it. ...
  3. If the file or folder that you want is stored within another folder, double-click the folder or a series of folders until you locate it. ...
  4. When you find the file you want, double-click it.
Jun 22, 2017

What is the path function in MATLAB? ›

What Is the MATLAB Search Path? The search path, or path is a subset of all the folders in the file system that MATLAB uses to locate files efficiently. Interactively add and remove folders, and change the order of folders on the search path, for the current MATLAB session and for future MATLAB sessions.

How do I find all files of a type? ›

Into search bar in Windows explorer simply type an asterisk followed by dot and extension and press enter. for example to find executable files, type *.exe and press enter.

What command shows all files? ›

When you type dir and press Enter in the Command Prompt, it lists all the files and directories in the current directory. By default, it displays the file name, size, and modification date and time.

How do I search across files in MATLAB? ›

On the Project tab, click the down arrow to expand the Tools gallery. Under Project Files, click Search. Alternatively, type in the file filter box, and the project provides a link to try searching inside files instead. In the Search Inside Project Files dialog box, enter some characters to search for.

What is files and function? ›

Answer: file is an object on a computer that stores data, information, settings, or commands used with a computer program. In a GUI (graphical user interface), such as Microsoft Windows, files display as icons that relate to the program that opens the file.

What is a function function in MATLAB? ›

MATLAB function functions evaluate mathematical expressions over a range of values. They are called function functions because they are functions that accept a function handle (a pointer to a function) as an input. Each of these functions expects that your objective function has a specific number of input variables.

How do I run a function file in MATLAB? ›

Go to the Editor tab and click Run . MATLAB® displays the list of commands available for running the function. Click the last item in the list and replace the text type code to run with a call to the function including the required input arguments.

How to check where a function is called in MATLAB? ›

str = which( item ) returns the full path for item to str . str = which( fun1 ,'in', fun2 ) returns the path to function fun1 that is called by file fun2 . Use this syntax to determine whether a local function is being called instead of a function on the path. This syntax does not locate nested functions.

How to find position in MATLAB? ›

Direct link to this answer
  1. You can use the “find” function to return the positions corresponding to an array element value. For example:
  2. To get the row and column indices separately, use:
  3. If you only need the position of one occurrence, you could use the syntax “find(a==8,1)”.
Feb 14, 2018

How do you find the area of a function in MATLAB? ›

area( X , Y ) plots the values in Y against the x-coordinates X . The function then fills the areas between the curves based on the shape of Y : If Y is a vector, the plot contains one curve. area fills the area between the curve and the horizontal axis.

How to get information about a function in MATLAB? ›

Select a function name in the Editor, Command Window, or Help browser; right-click; and then select Help on Selection. After you type an open parenthesis for function inputs, pause or press Ctrl + F1. Use the help command. Click the function icon to the left of the command prompt.

References

Top Articles
Latest Posts
Article information

Author: Eusebia Nader

Last Updated:

Views: 5785

Rating: 5 / 5 (80 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Eusebia Nader

Birthday: 1994-11-11

Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

Phone: +2316203969400

Job: International Farming Consultant

Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.