Everything is a Matrix
In MATLAB, even a single number (a scalar) is stored as a 1x1 matrix.
matlab
Matrix Creation
You create matrices using square brackets
[ ].- Use spaces or commas to separate elements in a row.
- Use semicolons to separate rows.
matlab
1-Based Indexing
Wait! This is the most important thing for programmers coming from other languages. In MATLAB, indexing starts at 1, not 0.
matlab
Common Data Types
| Type | Description |
|---|---|
| double | Default type for all numbers (64-bit float) |
| single | 32-bit floating point |
| int8 / int16 / ... | Signed integers of various sizes |
| char | Character arrays (for text) |
| string | Modern string objects (for text) |
| logical | true (1) or false (0) |
Cells and Structs
- Cell Array: A matrix where each element can be a different type or size. Use curly braces
{ }. - Struct: A structure with named fields (like a class or a dictionary).
matlab
Summary
| Term | Description |
|---|---|
| [ ] | Syntax for creating a matrix |
| ( ) | Syntax for accessing matrix elements |
| { } | Syntax for creating/accessing cell arrays |
| ; | Suppress output in the command window |
| ans | Default variable name for results not assigned to a variable |
| Best For | Efficiently handling mathematical and physical data |
| Logic | "Matrix-first" design |
| Safety | Out-of-bounds access is caught immediately |
| Modern | The string type is now preferred over char arrays |
| Standard | Use snake_case for variables by convention |
| Identity | High-precision numeric computing |