Presentation is loading. Please wait.

Presentation is loading. Please wait.

Writing functions in MATLAB

Similar presentations


Presentation on theme: "Writing functions in MATLAB"— Presentation transcript:

1 Writing functions in MATLAB
Functions are like scripts, only more flexible Functions are defined by their input and their output All variables that are declared within a function are erased after the function is executed; only the input and output variables survive Write the function triple from p. 34 of Matlab for Neuroscientists Inputs Function Outputs --turn to p. 34 in MfN and work through their simple example of the function 'triple'; extend it by doing 'tripleandquadruple' --point out that variables used within the function are not available after the function call; this differs from a script --talk abt. Paths to functions

2

3 Command window y=triple(x);
Function m-file function r=triple(n) r=3*n; end Variables in main workspace Variables in function space x x copied to n r is copied to y r is computed r and n are destroyed

4 Write a function which computes length of the hypotenuse of a triangle (what are inputs and outputs?)


Download ppt "Writing functions in MATLAB"

Similar presentations


Ads by Google