Things You'll Need
Instructions
Click the Matlab icon on your desktop and wait until Matlab has started up.
Click the "File" button in the top-left hand corner of the Matlab development environment. Click "New" in the drop-down menu. The Matlab "Editor" window will open. Click inside the "Editor" window so the cursor is visible.
Type the word "function" in the Editor window. Type the name of the output within square brackets. In the case of this example, this is "[ average ]". Type an equal sign and the name of your function. In this case, it is: " = meanaverage(x);".
Press the "Enter" key on your keyboard. On the next line, type the definition of the function. In this case, it is: "n = length(x); s = sum(x); average = s/n;".
Click the "File" tab in the top-left corner of the Editor window. Click "Save As" on the resulting drop- down menu. Type "meanaverage" in the "Save As" dialogue box. This will create a Matlab file called "meanaverage.m" that contains a function used in Matlab code or in other Matlab files.