Open In App

Data Type Conversion in MATLAB

Last Updated : 22 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Data Types in MATLAB is the upheld information organizes that are utilized for calculation. MATLAB is a well-known numerical and factual information investigation instrument that has a large number of elements for calculation. The different kinds of data type MATLAB supports are numeric types, characters, strings, date and time, tables, timetables, Structures, Cell Arrays, Map Containers, Time series, Data type Identification, and Data type transformation. Every one of the data types acknowledges and processes a specific sort of information design through the factors. MATLAB gives the functionalities to change over one data type to another viable data type utilizing the conversion capabilities.

MATLAB Data Types:

  • Numeric Types
  • Characters and Strings
  • Date and Time
  • Categorical Arrays
  • Tables
  • Structures
  • Cell Arrays
MATLAB Data Types

 

1. Numeric Types: Under this kind comes Integer and floating-point.

2. Characters and Strings: Text is addressed in character exhibits and string clusters.

3. Dates and Time: This contains varieties of date and time values which can be again displayed in a wide range of configurations like DD/MM/YYYY or MM/DD/YY and so on.

4. Categorical Arrays: Under this comes varieties of subjective information, for example, a rundown with values from a limited arrangement of discrete examined or information of the sort non-numeric.

5. Tables: Arrays are addressed here in an even structure whose named segments might contain various sorts, for example, numeric, straight out, and so on.

6. Structures: Most adaptable as well as mind-boggling, this type contains exhibits with named fields that contain changing sorts and sizes.

7. Cell Arrays: This again is an information type where a cluster can contain information of variable sorts and sizes.

8. Capability Handles: Such information types permit factors to by implication called a capability.

Conversion of Data Types in MATLAB:

  • int2str: It converts from integer data to the string.
  • mat2str: It converts from a matrix to a string.
  • num2str: It converts from number to string.
  • str2double: It converts from string to double-precision value.
  • str2num: It converts from string to number.
  • base2dec: It converts from base N number string to decimal number.
  • dec2base: It converts from decimal to base N number in string.

Example:

Matlab




/* MATLAB code for data type conversion */
  
inttostr = int2str(22)
% For Integer to String
  
mattostr = mat2str([3.84 2.81; 6.74 9.99]) 
% For Matrix to String
  
numtostr = num2str(pi) 
% For Number to String
  
strtodouble = str2double('4.5534'
% For String to Double
  
strtonumber = str2num('24'
% For String to Number
  
basestr = '1A'
basetodecimal = base2dec(basestr,12) 
% For Base to Decimal
  
number = 22;
decimaltobase = dec2base(number,12) 
% For Decimal to Base


Output:

 

 



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads