Presentation is loading. Please wait.

Presentation is loading. Please wait.

Announcements.

Similar presentations


Presentation on theme: "Announcements."— Presentation transcript:

1 Announcements

2 Announcements If You Would Like to Change Your Major to Computer Science, Please Let Me Know (Because we can get you help) Hotlines Support Groups De-programming Camps If You Would Like to Change Your Major to Computer Science, Please Don't Let Anyone Else Know (For Your Own Good)

3 Functions Command Window or M File with Function Script File
displayHi.m function z = displayHi() disp('Hi'); displayHi();

4 Functions Function: A Discrete Piece of Code that Performs a Specific Operation or Task Called procedure, module, method in other languages Named with a Descriptive Identifier; Stored in FunctionName.m File Called from Command Window or Scripts When Called, Program Control (Execution) Is Transferred to the Function Function Performs Required Tasks, and then Possibly Returns a Value After Return from Function, Control Returns to the Statement Following the Function Call

5 Function Attributes Function Name: Identifier Used to Call Function
Function Parameter(s) or Argument(s): Value(s) Passed into Function for Use by Function Code Function Return Value: Value Returned by Function Back to Calling Function

6 Function Parameters (Arguments)
May Pass as Many Parameters as Necessary to Function A Copy of the Value of the Parameter Is Passed to the Function Changing the Value of the Parameter in the Function Does Not Affect the Value of the Original Variable This Is Called Pass-by-Value

7 Declaring a Function In .m File Format : Example : myFunction.m :
function resultVar = myFunction(parameter(s)) Example : myFunction.m : function result = myFunction(x) result = x^2; result = result^2; Command Window : >> c = myFunction(2) c = 16

8 Another Function Example
myFunction2.m : function result = myFunction2(x,y) result = x^2 + y; Command Window : >> myFunction2(2,3) ans = 7

9 Arrays Array – Set of Values with One Name MatLab Creation :
arrayName = [ 1,3,5 ]; Vector – One Dimensional Array Matrix – Two Dimensional Array Element – One Member (Value) in an Array Offset or Subscript – location of an Element in and Array (in MatLab, starting with 1) Row Vector - “Row” of Values Column Vector - “Column” of Values

10 Creating Arrays – Row Vector
>> rowV(2) ans = 3

11 Creating Arrays – Column Vector
>> colV = [ 2; 4; 6 ] colV = 2 4 6 >> colV(3) ans =

12 Transpose (') Operator >> rowV' ans = 1 3 5 >> colV'

13 Offsetting with Variable
3 >> colV(offset) ans = 6

14 Array Example >> for k = 1:10 newRow(k) = k^2; end

15 Colon Operator % [Start:Step:End] >> rowV = [10:5:50] rowV =
>> rowV = [10:5:49] >> rowV = [10:15]

16 linspace() Function % linspace(Start, End, NumValues)
>> rowV = linspace(10,50,5) rowV =

17 Adding Elements to Vectors
% linspace(Start, End, NumValues) >> rowV = linspace(10,50,5) rowV = >> rowV(6) = 5555 >> newRowV(4) = 1000 newRowV =

18 Adding Vectors to Vectors
>> rowV = [ 1, 3, 5]; >> rowV2 = [ 7, 9, 11, 13]; >> rowVadd = [rowV, rowV2] rowVadd =

19 Offset Errors >> rowVadd(8) Index exceeds matrix dimensions.
Subscript indices must either be real positive integers or logicals. >> rowVadd(1.5) >> rowVadd(8) = 77 rowVadd =


Download ppt "Announcements."

Similar presentations


Ads by Google