MATLAB For Dummies, 2nd Edition
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:

 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.


About This Article

This article is from the book:

About the book authors:

Jim Sizemore is professor of physics and engineering at Tyler Junior College. For over 25 years, Sizemore has worked in the semiconductor and software industries as a process engineer, device physicist, and software developer. John Paul Mueller has written more than 100 books and more than 600 articles on topics ranging from functional programming techniques to application development using C++.

This article can be found in the category: