Module 2 of 8

MATLAB Functions

5 lessons  ·  Built-in functions, arguments, results display

1

Functions introduction

Topics covered

  • Syntax of a function with single input and single output
  • Basic trig functions and their inverses (cos, sin, etc.)
  • Nothing must come between the function name and parentheses — e.g. cos3(theta) and tan-1(theta) are invalid
  • Simple use of data analysis functions
  • sum(), min(), max(), sort(), median(), mean()
2

Functions extended

Topics covered

  • Syntax of a function with multiple inputs and/or multiple outputs
  • Examples using data analysis functions
  • Using a function as an argument of another function
3

Using additional function arguments

Topics covered

  • Specifying function arguments to change function behaviour (e.g. dim and 'all' with sum())
  • User-defined input function option 's'
5

Results display

Topics covered

  • Semi-colons to suppress output
  • disp() function and num2str() function
  • fprintf() function
  • Strings use single quotation marks, not double
  • Syntax of fprintf (format specification, variables)
  • Example using area of a circle
  • End line character \n
  • format long, format bank, etc.