VOOZH about

URL: https://www.geeksforgeeks.org/matlab/matlab-data-types/

⇱ MATLAB - Data Types - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

MATLAB - Data Types

Last Updated : 4 Jul, 2021

MATLAB is a platform which provides millions of Engineers and Scientists to analyze data using programming and numerical computing algorithm and also help in creating models. Data types are particular types of data items defined by the values they can store in them, generally, in programming languages they are used.

Define data types in MATLAB

In MATLAB we do not require any type of declaration statement, when it gets any new variable name it creates the variable and allocates appropriate memory space to it but if the variable name already exists it will replace the original content with new content and allocate it to new storage space when required. 

Syntax: variable name = a value (or an expression)

Example:

Output:

πŸ‘ Image

Data Types in MATLAB

In MATLAB data can be stored in different types, numeric, text, complex number, etc. To store these data MATLAB has different classes which have various characteristics. MATLAB provides a total of 16 fundamental data types.

πŸ‘ Image

Logic Type

Logic types are True and false values that are represented with the logical value 0 and 1. Any numerical value (non-complex) can be converted into a logical representation.

Syntax:G = logical (x)

Example:

Output:

πŸ‘ Image

Char and String type

In MATLAB character and string array provide storage for text type data. The strings are character array compared with the sequence of numbers called a numeric array.

Syntax: s = β€˜String’

Example:

Output:

πŸ‘ Image

Numeric Type-

 Integer and floating-point data are in this type with the following descriptions.

Data TypeShort DescriptionFeatures
doubleDouble-precision arrays
  • Default numeric data type (class) in MATLAB
  • Stored as 64-bit (8-byte) floating-point value
  • Range:

            Negative numbers = -1.79769 x 10308 to -2.22507 x 10-308

            Positive numbers = 2.22507 x 10-308 to 1.79769 x 10308

singleSingle-precision arrays
  • Stored as 4-byte (32-bit) floating-point value
  • Range-

            Negative numbers = -1.79769 x 10308 to -2.22507 x 10-308

            Positive numbers = 2.22507 x 10-308 to 1.79769 x 10308

int88-bit signed integer arrays
  • Stored as 1-byte (8-bit) signed integers
  • Range is -27 to 27-1
int1616-bit signed integer arrays
  • Stored as 2-byte (16-bit) signed integers
  • Range -215 to 215 -1
int3232-bit signed integer arrays
  • Stored as 4-byte (32-bit) signed integers
  • Range is -231 to 231-1
int6464-bit signed integer arrays
  • Stored as 8-byte (64-bit) signed integers
  • Range is -263 to 263-1
uint88-bit unsigned integer arrays
  • Stored as 1-byte (8-bit) unsigned integers
  • Range is 0 to 28-1
unit1616-bit unsigned integer arrays
  • Stored as 2-byte (16-bit) unsigned integers
  • Range is 0 to 216 -1
uint3232-bit unsigned integer arrays
  • Stored as 4-byte (32-bit) unsigned integers
  • Range is 0 to 232-1
uint6464-bit unsigned integer arrays
  • Stored as 8-byte (64-bit) unsigned integers
  • Range is 0 to 264-1

Example:

Output:

πŸ‘ Image

Table

The table contains rows and column variables. Each variable can be of different data types and different sizes, but each variable needs to have the same number of rows. Range of functions are used to access data to create, edit, and read the table data.

Syntax:T = table(ColumnName1,ColumnName2);

Example:

Output:

Table array
2x3
 Name QuestionAttempted CodingScore
 Atul Sisodiya 22 100

Cell

A cell array is a MATLAB data type that contains indexed data containers called cells. Cells can contain any type of data, commonly contain character vectors of different lengths, numbers, an array of numbers of any size. Sets of cells are enclosed in () and access to the cells is done by using {} which is to create, edit or delete any cell functions.

Syntax: c = { }

Example:

Output:

πŸ‘ Image

Structure

In structure data containers are used to group related data and their type, which are called fields. Fields may contain any type of data. In structures, Data is accessed using the dot notation.

Syntax: structname.fieldName

Example:

Output:

πŸ‘ Image

Function Handles

Function Handles is majorly used in MATLAB is to pass a function (numerical or char) to another function. Variables that are used to invoke function indirectly can be named as a Function handle.

To create a function handle β€˜@’ operator is used.

Example: To create a function handle to evaluate x^2 + y^2, a function used is:

Output:

πŸ‘ Image
Comment