MATLAB For Dummies
Book image
Explore Book Buy On Amazon

You have a shiny new MATLAB function and you’re just itching to use it. Before you can use the function, you must make sure that the directory containing the function file is part of the MATLAB path. You can achieve this goal in two ways:

  • Double-click the directory entry in the Current Folder window.

  • Right-click the directory entry in the Current Folder window and choose Add to Path→Selected Folders and Subfolders from the context menu.

You can try your new function in a number of ways. The following lists contains the most common methods:

  • Click Run in the Editor window, and you see the output in the Command window. However, there is a little twist with functions. You can’t always click Run and get a successful outcome, even though the function will always run.

  • Click Run and Advance in the Editor window. (This option runs the selected section when you have sections defined in your file.)

  • Click Run and Time in the Editor window. (This option outputs profiling information — statistics about how the function performs — for the function.)

  • Type the function name in the Command window and press Enter.

Your function also has help available with it. Type help(‘SayHello') and press Enter. MATLAB displays the following help information:

SayHello()
 This function says Hello to everyone!

The output is precisely the same as it appears in the function file. The doc() function also works. Type doc(‘SayHello') and press Enter. Notice how the title is presented in a different color and font than the text that follows.

image0.jpg

About This Article

This article is from the book:

About the book authors:

John Paul Mueller is an author and technical editor with experience in application development, database management, machine learning, and deep learning. He has written hundreds of books and articles helping everyday people learn everything from networking to database management.

John Mueller has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services (AWS). Luca Massaron, a Google Developer Expert (GDE),??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques.

This article can be found in the category: