2. MATLAB Programming

Download this MathWorks provided quick reference on MATLAB: matlab-basic-functions-reference.pdf

MATLAB [1] (name taken from MATrix LABoratory) is a high-level programming language and development environment well suited for numerical problem solving, data analysis, prototyping, and visualization. MATLAB has become very popular with engineers, scientists, and researchers in industry and academia. Three features of MATLAB make it stand out:

  1. Matrix and vector support

  2. Data visualization tools

  3. Huge library of functions covering nearly every area of mathematics, science, and engineering.

MATLAB has extensive built-in documentation. It contains descriptions of the main functions, sample code, relevant demonstrations, and general help pages. MATLAB documentation can be accessed in several ways, including command-line help, a graphical documentation browser, and web pages.

MATLAB code that users write is interpreted, rather than compiled, so it is unnecessary to declare and allocate variables in memory before using them. Although MATLAB programs are interpreted, MATLAB has features that make it still execute relatively fast.

  1. When the code is vectorized (explained later), instead of using loops, the performance is better than expected for interpreted programs.

  2. MATLAB has an extensive library of functions to do most of the work in your program. When MATLAB functions are run, the computer is executing highly optimized, compiled code.

This chapter covers the basics of MATLAB programming. The intent is to start at the very beginning by letting readers start programming simple programs immediately. In later chapters, we will apply MATLAB to solve computational problems while introducing additional MATLAB features and applying them with examples. This chapter gives special attention to vectorized code using element-wise arithmetic, logical arrays, and vector-aware functions to operate at the vector and matrix level with limited need for loops operating on the individual values in arrays.

Contents: