Home

How to Use Your New MATLAB Function

|
Updated:  
2016-03-26 08:22:07
|
From The Book:  
MATLAB For Dummies
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 author:

Jim Sizemore is Professor of Physics and Engineering at Tyler Junior College. For over 25 years he s worked in the semiconductor and software industries as a process engineer, device physicist, and software developer and has been teaching college physics, engineering, and math for the last 13 years.

John Paul Mueller is a freelance author and technical editor. He has writing in his blood, having produced 100 books and more than 600 articles to date. The topics range from networking to home security and from database management to heads-down programming. John has provided technical services to both Data Based Advisor and Coast Compute magazines.