Overview of Data Types in MATLAB
In this data types in MATLAB article, we shall provide a very basic introduction to MATLAB and would mainly talk about its data types. MATLAB is one of the most famous software tools for numeric programming and is widely used across the world. It is developed by MathWorks and probably the most favorite software tool in academics and research purposes. MATLAB is used in almost all colleges and universities for higher education in science, technology, and engineering field. MATLAB is proprietary which means that one needs to purchase a license for using it.
Still compared to many other similar open-source technologies, MATLAB is quite market dominating and is well known for its faster execution speed, a vast set of libraries that support a huge domain of science and engineering and accuracy and reliability in its computation. The goal of this article would be to introduce MATLAB to its first-time user and make them familiarize with various simple know-how of using it.
MATLAB has the following 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 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.|
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 programing language. Each of these data types is very important and MATLAB users need to deeply understand the property and usages of each of this type 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 –