Presentation is loading. Please wait.

Presentation is loading. Please wait.

How To Create a Function in MATLAB English 393 Professor Harris May 10, 2011 Ava-Dawn Hammond Byung Kang Imelda Kwakye-Ackah Evelyn Ojo Adam Page.

Similar presentations


Presentation on theme: "How To Create a Function in MATLAB English 393 Professor Harris May 10, 2011 Ava-Dawn Hammond Byung Kang Imelda Kwakye-Ackah Evelyn Ojo Adam Page."— Presentation transcript:

1 How To Create a Function in MATLAB English 393 Professor Harris May 10, 2011 Ava-Dawn Hammond Byung Kang Imelda Kwakye-Ackah Evelyn Ojo Adam Page

2 Introduction MATLAB is a computer program used in data analysis, algorithms, plotting of graphs, creating functions, etc.

3 Audience Anyone who is not familiar with MATLAB.

4 Objective To create a function using MATLAB.

5 Types of Functions in MATLAB Primary Function: contains the main program. Sub-functions: subroutines to the main function. Sub-functions are written within the same file, but in different sections. Nested functions: Similar to sub-functions, but are contained within another function. Anonymous functions: Quick method to make a function from any MATLAB expression. This can be done from within another function or at the MATLAB command prompt. Overloaded functions: Useful when creating a function that responds to different input types. Private functions: Gives a way to restrict access to a function. They can only be called from a function in the parent folder.

6 In this tutorial… Primary function All other functions are specialized versions of the primary function.

7 Procedures This is a procedure to make a simple function that greets a user. STEP 1 Launch the MATLAB application STEP 2 Click [File] → [New] → [Function]

8 Procedure (cont.) STEP3 MATLAB will automatically create a new function with default setup. The First line is function line [output_args] – what gets returned when the function is called. untitled – the name of the function [input_args] – inputs required to perform

9 STEP 4 Assign a name for function that gives some idea of what it does. It should start with a letter, usually lowercase.

10 STEP 5 Save the function as a.m file File name should be exactly the same as the function name you made at STEP 4. MATLAB puts the function name on the “Save As” section by default helloWorld.m

11 STEP 6 Define the input and output parameters by naming them. If the function does not require any input, insert a tilda (~) in the input segment. Give a brief description of the function on line directly below the function line. Output Name Input Name Description

12 STEP 7 Lastly, insert all code necessary to perform the function’s goal. codes

13 MATLAB Functional Environment Group 1 Icons: A) Create new.m file B) Open a.m file C) Save current.m file D) magic buttons – cut, copy, paste, undo, and redo.

14 MATLAB Functional Environment Group 2 Icons: Used to navigate through the program A) goes to the previous section of code B) goes to the next section of code C) selects a function within the.m file. Convenient if the file contains sub-functions.

15 MATLAB Functional Environment Group 3 Icons: debugging tools A) runs the function using the saved run configuration B) sets or clears breakpoint at current line C) clears all breakpoint in all currently open files D) ways to step through code during debug mode

16 MATLAB Functional Environment Group 4 Icons: Used for cell mode. Cell mode allows programs to be sectioned into parts, which makes searching and reading easier A) insert a new cell block (section) B) display all cell block titles C) shows cell mode information

17 Reference Etter, Delores, and David Kuncicky. Introduction to MATLAB 7. 1 st ed. Upper Saddle River, NJ: Pearson Prentice Hall, 2005. 157-99. Print.


Download ppt "How To Create a Function in MATLAB English 393 Professor Harris May 10, 2011 Ava-Dawn Hammond Byung Kang Imelda Kwakye-Ackah Evelyn Ojo Adam Page."

Similar presentations


Ads by Google