Download presentation
Presentation is loading. Please wait.
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
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?)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.