Working with Data in MATLAB

1. Data Types

Data types (also referred to as classes) define the kind of data a variable can hold and the operations that can be performed on it.

  • Numeric Types

    • double: This is the default numeric data type in MATLAB. Suitable for general-purpose numerical computations where precision and range are important.
    • Integer Types: Whole numbers only, which require less memory but have less precision and limitations on certain mathematical operations compared to double.
  • Character and String Types

    • char: Character arrays for storing text created using single quotes.
    • string: String arrays, which are more flexible than character arrays and can be created using double quotes.
  • Logical Type

    • logical: Represents true or false values.

4b. Sets and Operators

Operator Description Example
Arithmetic
+ Addition a + b
- Subtraction a - b
* Matrix multiplication a * b
.* Element-wise multiplication a .* b
/ Matrix right division a / b
./ Element-wise right division a ./ b
\ Matrix left division a \ b
.\ Element-wise left division a .\ b
^ Matrix power a ^ b
.^ Element-wise power a .^ b
.' Transpose a.'
Relational
== Equal to a == b
~= Not equal to a ~= b
> Greater than a > b
< Less than a < b
>= Greater than or equal to a >= b
<= Less than or equal to a <= b
Logical
& Logical AND a & b
`\ ` Logical OR `a b`
~ Logical NOT ~a
xor Logical EXCLUSIVE OR xor(a, b)
Sets
union Union of two sets union(a, b)
intersect Intersection of two sets intersect(a, b)
setdiff Difference of two sets setdiff(a, b)
setxor Symmetric difference of two sets setxor(a, b)
ismember Determine if elements are members of a set ismember(a, b)
unique Unique elements in an array unique(a)

3. Suggested Tutorials

Tutorial: Mathematical and Statistical Operations with Arrays

Tutorial: Conditional Data Selection

Tutorial: Tables of Data

Tutorial: Organizing Tabular Data

Course: A tour of MATLAB Data Types

Course: Calculations with Vectors and Matrices

Course: Tables

Course: Find and Extract Subsets of Data

Course: Clean and Prepare Data for Analyses

Course: Calculations on Grouped Data

4. Supplemental Materials

Video: Introducing MATLAB Fundamental Classes

Live Demo: Data Types

Live Demo: Numbers

Live Demo: Strings

Documentation: Fundamental MATLAB Classes

Documentation: Data Types

Documentation: Operators and Elementary Operations

Andy's Brain Book: Variables and Structures

Next Page
Next Page