Organizing and Accessing Data in MATLAB
This reference shows common use cases, so it is not an exhaustive list.
| Representing Data | |||
|---|---|---|---|
| Homogenous | |||
| Data Type | Icon | Purpose | Syntax |
| Double, single, (u)int8, (u)int16, (u)int32, (u) int64, complex |
|
Numeric arrays, matrix computations, math | [1,2,3], [1;2;3], uint8(), int16() |
| String |
|
Text arrays | "hello world" |
| Char |
|
Single characters, character arrays | 'hello' |
| Categorical |
|
Discrete, nonnumeric data | categorical() |
| Datetime |
|
Absolute dates and timestamps, including time zones | datetime('July 12, 2001 08:15:01') |
| Duration |
|
Elapsed times | duration(h,m,s), hours(), minutes() |
| Calendar of duration |
|
Relative time based on calendar | caldays(), calweeks() |
| Logical |
|
True/false, test state, identify data by condition | logical(), ==, ~=, >, >=, <, <=, &, &&, |, || |
| Other specialized types |
|
sparse, enumeration, custom, … | » Documentation |
| Heterogeneous | |||
| Data Type | Icon | Purpose | Syntax |
| Table |
|
Mixed-type, column-oriented data (spreadsheet-like). Store metadata |
table(x,y,z), array2table |
| Timetable |
|
Timestamped tabular data | timetable(t,x,y) table2timetable,array2timetable |
| Structure |
|
Fields can contain data of any size and type. Ideal for nonrectangular data. | struct() |
| Cell array |
|
Each cell in the array can contain any data type, any size | cell(), {pi,ones(5), "hello"} |
| Tall array |
|
MATLAB data types can be made "tall" when data does not fit in memory | ds = datastore(), T = tall(ds) |
| Dictionary |
|
Object that maps unique keys to values | d = dictionary(keys,values) |
| Logical Indexing |
|---|
Use logical expressions to select data Elements of X greater than 7: Combine conditions Multidimensional arrays Tables and timetables |
| Container Indexing | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Using parentheses () for indexing retains the initial data type. Access the underlying data with curly braces {}. Tables and structures also allow you to reference data by name. | ||||||||||||||||
» Examples |
|
|||||||||||||||