Overview of 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
- 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-
- Numeric Types: Under this type comes Integer and floating-point or fraction data
- Characters and Strings: Text are represented in character arrays and string arrays
- 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.
- 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.
- Tables: Arrays are represented here in a tabular form whose named columns may contain different types such as numeric, categorical, etc.
- Timetables: Time-stamped data such as DD/MM/YYYY/HR/MIN/SEC in tabular form.
- Structures: Most versatile as well as complex, this type contains arrays with named fields that contain varying types and sizes.
- Cell Arrays: This again is a data type where an array can contain data of variable types and sizes.
- Function Handles: Such data types allow variables to call a function indirectly.
- 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.
- Time Series: Time series data has a specific type where data vectors are sampled over the time period.
- Data Type Identification: Such data types help us determine the data type of any variable.
- 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
|Int8||This is called 8 bits signed integer|
|Uint8||This is 8 bits unsigned integer|
|Int16||16 bits signed integer|
|Uint16||16 bits unsigned integer|
|Int32||32 bits signed integer|
|Uint32||32 bits unsigned integer|
|Int64||64 bits signed integer|
|Uint64||64 bits unsigned integer|
|Single||This is called single-precision numeric data|
|Double||This is double-precision numeric data|
|logical||The logical value of 0 or 1 represents true or false|
|char||Character data such as alphabets|
|Cell array||an array of indexed cells where each cell is capable of storing an array of the same or different dimensions and different data type|
|structure||This 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 handle||This acts as a pointer to a function|
|User classes||Such data types represent objects which are constructed from a user-defined class|
|Java classes||Such types represent objects which are constructed from a Java class.|
Below is the example
strg = 'Hello MATLAB!'
n = 234510
dbl = double(n)
unt = uint32(7891.50)
rrn = 15678.92347
cons = int32(rrn)
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
|char||This function converts from to character array (string)|
|int2str||This function converts from integer data to the string|
|mat2str||This function converts from a matrix to string|
|num2str||This function converts from number to string|
|str2double||This function converts from string to double-precision value|
|str2num||This function converts from string to number|
|native2unicode||This function converts from numeric bytes to Unicode characters|
|unicode2native||This function converts from Unicode characters to numeric bytes|
|base2dec||This function converts from base N number string to decimal number|
|bin2dec||This function converts from binary number string to decimal number|
|dec2base||This function converts from decimal to base N number in string|
|dec2bin||This function converts from decimal to binary number in string|
|dec2hex||This function converts from decimal to hexadecimal number in string|
|hex2dec||This function converts from hexadecimal number string to decimal number|
|hex2num||This function converts from hexadecimal number string to double-precision number|
|num2hex||This function converts from singles and doubles to IEEE hexadecimal strings|
|cell2mat||This function converts from cell array to numeric array|
|cell2struct||This function converts from cell array to structure array|
|cellstr||This function creates a cell array of strings from a character array|
|mat2cell||This function converts from array to cell array with potentially different sized cells|
|num2cell||This function converts from array to cell array with consistently sized cells|
|struct2cell||This function converts from structure to cell array|
- From the above discussion and example, we got a deep look into the various data types of MATLAB programming language. Each of these data types is very important and MATLAB users need to deeply understand the property and usages of each of these types to write efficient MATLAB programs that are fast, optimized for performance, and scalable for future needs.
- As a beginner, users are advised to practice a lot of these syntaxes so that they can understand their usages and relative advantages and disadvantages. Such coding practice is important to have great control over any language and to be able to write efficient MATLAB codes.
This has been a guide to Data Types in MATLAB. Here we discuss the introduction, list, and conversions of data types in MATLAB with an example. You can also go through our other suggested articles to learn more –