This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CS 100M Lecture 8 September 19, 2006 Topic: User-defined function, random numbers Reading: CFile Chapter 4 Script vs. function A script is an m-file that is executed line-by-line just as if we are typing it into the Command Window. The value of a variable in a script is stored in the Command Window Workspace . A function is an m-file with a function header (statement). It has its own private (local) function workspace that does not interact with the Command Window Workspace. Variables are not shared between workspaces even if they have the same name . General form of a user-defined function function [out1, out2, ...] = functionName( in1, in2, ... ) % 1-line comment to describe what the function does % Further description in additional lines of comments Executable code that at some point assigns values to output arguments out1 , out2 , ... in1 , in2 , ... are defined when the function begins execution. Variables out1 , out2 , ... are called function parameters and they hold the function arguments (values) when the function is invoked. out1 , out2 , ... are not defined until the executable code in the function assigns values to them. Look on-line for m-files drawColorDot.m , and polar2xy.m to see examples of functions that have multiple output arguments or no output argument. Pay attention to the function headers. A function header is the contract for how a function is to be called. Suppose you have a function with the following header:for how a function is to be called....
View Full Document
This note was uploaded on 03/15/2011 for the course COM S 100 at Cornell University (Engineering School).