Categories
1. Basics of Matlab

Data Types in MATLAB

Data Types in MATLAB are the supported data formats that are used for computation. MATLAB is a popular mathematical and statistical data analysis tool that has a wide range of features for computation. The various types of data type MATLAB supporting are numeric types, characters, strings, date and time, categorical arrays, tables, timetables, Structures, Cell Arrays, Functional Handlers, Map Containers, Time series, Data type Identification, Data type conversion. Each of the data types accepts and processes a certain type of data format through the variables. MATLAB provides the functionalities to convert one data type to another compatible data type using the conversion functions

Data Types in MATLAB

Following are the Data Types:-

  • Numeric Types
  • Characters and Strings
  • Date and Time
  • Categorical Arrays
  • Tables
  • Timetables
  • Structures
  • Cell Arrays
  • Functional Handles
  • Map Containers
  • Time Series
  • Data Type Identification
  • Data Type Conversion

Let’s see the significance of the individual Data Types in MATLAB in details-

  1. Numeric Types: Under this type comes Integer and floating-point or fraction data
  2. Characters and Strings: Text are represented in character arrays and string arrays
  3. Dates and Time: This contains arrays of date and time values which can be again shown in many different formats such as DD/MM/YYYY or MM/DD/YY etc.
  4. Categorical Arrays: Under this comes arrays of qualitative data such as a list with values from a finite set of discrete sampled or data of the type non-numeric.
  5. Tables: Arrays are represented here in a tabular form whose named columns may contain different types such as numeric, categorical, etc.
  6. Timetables: Time-stamped data such as DD/MM/YYYY/HR/MIN/SEC in tabular form.
  7. Structures: Most versatile as well as complex, this type contains arrays with named fields that contain varying types and sizes.
  8. Cell Arrays: This again is a data type where an array can contain data of variable types and sizes.
  9. Function Handles: Such data types allow variables to call a function indirectly.
  10. Map Containers: Similar to the dictionary in many languages, such data types have objects with keys where the key is indexed to values, where keys need not be integers.
  11. Time Series: Time series data has a specific type where data vectors are sampled over the time period.
  12. Data Type Identification: Such data types help us determine the data type of any variable.
  13. Data Type Conversion: Using such types, we can convert between many data types such as numeric arrays, cell arrays, character arrays, structures, function handles, and tables, etc.

Now let’s look into each type with more details

Data TypesDefinition
Int8This is called 8 bits signed integer
Uint8This is 8 bits unsigned integer
Int1616 bits signed integer
Uint1616 bits unsigned integer
Int3232 bits signed integer
Uint3232 bits unsigned integer
Int6464 bits signed integer
Uint6464 bits unsigned integer
SingleThis is called single-precision numeric data
DoubleThis is double-precision numeric data
logicalThe logical value of 0 or 1 represents true or false
charCharacter data such as alphabets
Cell arrayan array of indexed cells where each cell is capable of storing an array of the same or different dimensions and different data type
structureThis is more like a C structure where each structure has a named field which is capable of storing an array of different size or dimension and different data types
Function handleThis acts as a pointer to a function
User classesSuch data types represent objects which are constructed from a user-defined class
Java classesSuch types represent objects which are constructed from a Java class.

Examples:

Below is the example

Code:

strg = 'Hello MATLAB!'
n = 234510
dbl = double(n)
unt = uint32(7891.50)
rrn = 15678.92347
cons = int32(rrn)

Output: –

strg = Hello MATLAB!n = 234510dbl = 234510unt = 7901rrn = 15678.9cons = 15679
  • In the above example, strng is string data type, n is numeric data type, dbl is double data type, unt is 32 bit unsigned integer, rrn is fractional data which is converted to int 32 integer and stored as cons.

Conversion of Data Types in MATLAB

FunctionPurpose
charThis function converts from to character array (string)
int2strThis function converts from integer data to the string
mat2strThis function converts from a matrix to string
num2strThis function converts from number to string
str2doubleThis function converts from string to double-precision value
str2numThis function converts from string to number
native2unicodeThis function converts from numeric bytes to Unicode characters
unicode2nativeThis function converts from Unicode characters to numeric bytes
base2decThis function converts from base N number string to decimal number
bin2decThis function converts from binary number string to decimal number
dec2baseThis function converts from decimal to base N number in string
dec2binThis function converts from decimal to binary number in string
dec2hexThis function converts from decimal to hexadecimal number in string
hex2decThis function converts from hexadecimal number string to decimal number
hex2numThis function converts from hexadecimal number string to double-precision number
num2hexThis function converts from singles and doubles to IEEE hexadecimal strings
cell2matThis function converts from cell array to numeric array
cell2structThis function converts from cell array to structure array
cellstrThis function creates a cell array of strings from a character array
mat2cellThis function converts from array to cell array with potentially different sized cells
num2cellThis function converts from array to cell array with consistently sized cells
struct2cellThis function converts from structure to cell array

Leave a Reply

Your email address will not be published. Required fields are marked *