lecture 1

Aug 28, 2025

Overview

This lecture introduced basic data structures and concepts in MATLAB, demonstrated variable creation and array handling, and provided instructions for accessing and using MATLAB in the DVC environment. The session also included steps for creating and submitting your first MATLAB script.

MATLAB Data Structures

  • MATLAB organizes data in arrays (rows and columns).
  • An array is referenced by a single name and indexed by row and column (e.g., arr(3,2) is row 3, column 2).
  • Arrays start indexing at 1 (not 0).
  • Vectors are one-dimensional arrays (either row or column).
  • Matrices are two-dimensional arrays (multiple rows and columns).
  • The size of an array is specified as number of rows × number of columns (e.g., 4 × 5).

Referring to Array Elements

  • Elements can be accessed by a single index (column-wise order) or by two indices: arr(row, column).
  • Element numbers count across columns first in MATLAB.

Variables and Naming Rules

  • Variables represent named memory locations for storing data.
  • Variable names must start with a letter and can include numbers and underscores only.
  • Names are case sensitive (e.g., Name ≠ name).
  • Avoid using MATLAB keywords or function names as variable names.
  • MATLAB only uses the first 31 characters of a variable name.

Data Types

  • Double: For decimal numbers (default, 64-bit, up to 15 decimal places).
  • Complex: Numbers with real and imaginary parts (e.g., 1 + i).
  • Char: For single characters or strings.
  • Character arrays (strings) are arrays of char data.

Creating and Initializing Arrays

  • Assignment uses = (assignment operator).
  • Arrays use square brackets []; elements are space- or comma-separated, rows separated by semicolons.
  • All rows in an array must have the same number of elements.
  • The colon operator (e.g., 1:2:9) creates arrays with specified start, increment, and end values.
  • The transpose operator (') switches rows and columns.
  • linspace(start, end, num) creates linearly spaced arrays.
  • logspace(start, end, num) creates logarithmically spaced arrays.
  • zeros(n, m) and ones(n, m) create arrays filled with zeros or ones.

User Input and Initialization

  • The input function prompts the user to enter values at runtime.
  • Adding 's' as a second argument to input reads string input.

MATLAB Programming Environment

  • MATLAB opens with three main windows: Command Window, Current Folder, and Workspace.
  • Command Window: main interface for executing commands interactively.
  • Scripts (saved with .m extension) allow batch execution of commands.
  • Use semicolons ; to suppress output in the Command Window.
  • format compact removes extra blank lines in output.
  • Use the up/down arrow keys to recall previous commands.
  • Comments start with % and are ignored during execution.

Working Remotely with MATLAB

  • Access DVC computers remotely via idm.dvc.edu using your DVC login.
  • Save and upload your script before disconnecting or email it to yourself to avoid data loss.
  • Always sign out after your remote session to avoid access issues.

Key Terms & Definitions

  • Array — A data structure organizing values in rows and columns.
  • Vector — A one-dimensional array (row or column).
  • Matrix — A two-dimensional array.
  • Variable — A named storage location for data.
  • Assignment Operator = — Assigns values to variables.
  • Colon Operator : — Creates sequences with a specified increment.
  • Script — A file (*.m) containing a sequence of MATLAB commands.
  • Command Window — Interface for entering and executing MATLAB commands.
  • Workspace — Displays variables currently in memory.

Action Items / Next Steps

  • Complete Assignment 1: Type (do not copy-paste) the given script, run it, paste output as comments, and upload your .m file while connected.
  • Review lecture slides and MATLAB environment access instructions.
  • Practice creating arrays, variables, and simple scripts using the DVC MATLAB system.