% ECE 1250 S12 Lecture M11 % Today's lecture focuses on writing functions. (See the .m files associated % with this lecture.) The idea is that we can write our own functions. For % example, we can write mathematical functions or our own choosing. Or we % can write functions that create sound effects, (as in our final lab % assignment). % The following are requirements of a function file: % An example of the first line is the following: % function [a, b] = funcname(n, m, p) % 1) The first word in the file must be the word "function" % 2) After the word function are names of values to be returned by the function. % If there is more than one return value, they are placed inside square % brackets, [ ], and separated by commas. % 3) After the return variables is an equal sign, =. % 4) After the equal sign is the function name. The name of the file containing % the function should be, for example, funcname.m % 5) After the function name are values to be handed into the function by the % program that calls the function. The values are placed inside parentheses, % ( ), and separated by commas. If there are no input values, then funcname % is the last thing on the line. (That is, there are no parentheses at all.) % After the first line are comments that will be typed out in response to the % user typing "help funcname" at the command prompt. Anything after the first % blank line in the file will not be printed out in the help command. % Any global variables should be declared after the help command comments. % The function's instructions that carry out the purpose of the function follow % the global varialbes. These instructions will set the values of the % variables returned by the function or carry out other actions such as % plotting. % An "end" statement ends the function. % Some example functions: % parallel_R.m Compute value of parallel resistors: parallel_R(R1,R2) %-------------------------------------------------------------------------------- % standard_R.m standard_R(R_array) R_array = values of R's, each value 10 to 99 ohms %----------------------------------------------------------------------------------------- % vibrato.m %--------------------------------------------------------------------------------