MATLAB Basics and Environment — Study Notes Summary & Study Notes
These study notes provide a concise summary of MATLAB Basics and Environment — Study Notes, covering key concepts, definitions, and examples to help you review quickly and study effectively.
🖥️ Overview of the MATLAB Environment
MATLAB (Matrix Laboratory) is an interactive environment for numerical computation, visualization, and programming. The interface is organized around a few core panels that you will use frequently: Command Window, Workspace, Editor, and Current Directory. Understanding how these pieces fit together helps you develop, run, and manage code efficiently.
🧩 Command Window
The Command Window is where you enter commands and see immediate results. Use it for quick calculations, testing expressions, and running small scripts.
- Enter a command and press Enter to execute. Example: or .
- Use the up/down arrow keys to browse command history.
- End a line with a semicolon
;to suppress output; omit it to display results.
📦 Workspace
The Workspace shows all current variables and their sizes/types. It’s a snapshot of the current session state.
- You can inspect variable values, sizes, and classes at a glance.
- Clear variables with
clearorclear varNameto free memory. - Save or load variables using
saveandload(see file management section).
✍️ Editor
The Editor (also called MATLAB Editor or Live Editor for rich documents) is where you write, edit, and debug code.
- Create script files (.m) to run sequences of commands.
- Create function files (.m) when you need reusable code with input/output arguments.
- Use breakpoints and the debugger to step through code and inspect variables.
📁 Current Directory & Path
The Current Directory determines where MATLAB looks for files by default and where it saves output when no path is specified.
- Change directory with
cd folderNameor use the Current Folder browser. - MATLAB searches folders on its path to find functions and scripts. Add folders using
addpathor the Set Path GUI.
🔢 Entering Matrices and Vectors
MATLAB treats most data as arrays (vectors, matrices, multidimensional arrays).
- Row vector:
- Column vector:
- Matrix:
- Indexing: access elements with parentheses: is row 2, column 1.
- Colon operator: produces ; use to select the entire 2nd column.
- Transpose: gives the transpose (for numeric arrays).
🔤 Creating Variables & Workspace Management
Create variables simply by assigning values: x = 10; or name = 'Alice';.
- Variable names are case-sensitive and must start with a letter, followed by letters, digits, or underscores.
- Inspect variable contents using
whosfor detailed list,whofor names only. - Remove variables with
clear varNameorclearto remove all variables. - Use
save filenameto save workspace variables to a.matfile andload filenameto restore them.
🧮 Basic Arithmetic & Using MATLAB as a Calculator
MATLAB evaluates arithmetic expressions following standard precedence.
- Basic operators:
+,-,*(matrix multiply),/(matrix right divide),^(power). - Elementwise operations use a dot:
.*,./,.^for element-by-element multiply/divide/power. - Examples:
y = 2 + 3*4;,B = A .* 2; - Use the colon
:and functions likesum,mean, andmaxfor vectorized operations.
📚 Built-in Functions & Constants
MATLAB provides many built-in functions and constants for math, statistics, and engineering.
- Common functions:
sin,cos,tan,exp,log,sqrtused likesin(pi/2)orsqrt(4). - Constants:
piis available aspi. - Use
help functionNameordoc functionNameto read usage and examples (e.g.,help sin). - Many specialized toolboxes extend available functions for signal processing, optimization, etc.
💾 Managing Files and Directories (save, load, cd, path)
File and directory management keeps projects organized and reproducible.
cd folderPathchanges the Current Directory.pwdshows the present working directory.save filenamewrites variables tofilename.mat;save filename var1 var2saves specific variables.load filenameloads variables from a.matfile into the Workspace.addpath folderPathandrmpath folderPathadjust the function search path. Usesavepathto persist changes.
📜 Script Files vs. Function Files
Understand when to use scripts and when to write functions.
- Script files (.m) contain a sequence of MATLAB commands and operate on the base workspace. Use scripts for simple workflows and quick experiments.
- Function files define a function with inputs and outputs using the
functionkeyword. Functions have their own local workspace and are reusable and safer for modular code.- Example function header:
function out = myFunc(in1, in2)
- Example function header:
- Prefer functions for modularity, testing, and reuse; use scripts for orchestration and interactive work.
✅ Quick Tips & Common Commands
help <name>anddoc <name>— documentation.clc— clear Command Window.clear/clearvars— clear variables.who/whos— list variables.edit filename— open or create an m-file in the Editor.- Use vectorized operations instead of loops where possible for speed.
These notes cover the essentials to get started with MATLAB: navigating the interface, creating and managing variables, performing arithmetic and matrix operations, using built-in functions, handling files, and understanding the distinction between scripts and functions. Practice by creating small scripts and functions, exploring the Workspace, and consulting help/doc as needed.
Sign up to read the full notes
It's free — no credit card required
Already have an account?
Create your own study notes
Turn your PDFs, lectures, and materials into summarized notes with AI. Study smarter, not harder.
Get Started Free