{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

class5b_matlab_activities_engr195(II)s10

# class5b_matlab_activities_engr195(II)s10 - ENGR 195(II...

This preview shows pages 1–2. Sign up to view the full content.

Input Vector Vector Average [1:1:10] [12 27 3 54 31] Temperature1 Result Temperature2 Result 1. row 2, column 3 2. row 3, column 2 ENGR 195(II) – Spring 2010 Activity 1 Class 5b Activity 1 – User-Defined Function (Estimated Time = 20 minutes) You will write a user-defined function that calculates the average of a vector. o The input argument for the function will be a vector. o The output argument will be the average of the vector. o The code will calculate the average using the SUM() and LENGTH() functions. A. Open function_header_template.m in the MATLAB editor and re-save as vector_avg.m. This will become the user-defined function vector_avg . 1. On the first line, before the help lines provided in the function_header_template.m file, write the function definition. The general format is: function [output variables] = function_name(input variables) for example: function [average_value] = vector_avg(my_vector) 2. Immediately following the function definition, edit the comment lines that describe authorship and help a user learn how to implement your user-defined function. You should clearly list all required input and output arguments with comments that explain each. Use the following format: % FUNCTION NAME Very brief purpose of function on this line % INPUTS: List them below one line per input argument % % OUTPUTS: List them below one line per output argument % Save your function file and check that you have provided proper help comments by typing help vector_avg at the MATLAB prompt. (Your identification and date information and all help information should be echoed in the command workspace.) 3. Following the comments, write the code necessary to calculate the average of a vector using the sum and length commands.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}