EDUCBA

EDUCBA

MENUMENU
  • Explore
    • Lifetime Membership
    • All in One Bundles
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign up
Home Data Science Data Science Tutorials Matlab Tutorial Data Types in MATLAB

Data Types in MATLAB

Priya Pedamkar
Article byPriya Pedamkar

Updated March 20, 2023

Data Types in MATLAB

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

ADVERTISEMENT
Popular Course in this category
MATLAB Course Bundle - 5 Courses in 1 | 3 Mock Tests

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

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 Types Definition
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.

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

Function Purpose
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

Conclusion

  • 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.

Recommended Articles

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 –

  1. Matlab Operators
  2. Getting Started with Applications of Matlab Commands
  3. Career in MATLAB
  4. MATLAB Interview Questions
  5. Matlab Compiler | Applications of Matlab Compiler
ADVERTISEMENT
SPSS Course Bundle - 14 Courses in 1 | 5 Mock Tests
34+ Hours of HD Videos
14 Courses
5 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
MICROSOFT AZURE Course Bundle - 15 Courses in 1 | 12 Mock Tests
63+ Hour of HD Videos
15 Courses
12 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
HADOOP Course Bundle - 32 Courses in 1 | 4 Mock Tests
125+ Hour of HD Videos
32 Courses
4 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
ADVERTISEMENT
INFORMATICA Course Bundle - 7 Courses in 1
47+ Hours of HD Videos
7 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Footer
Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
  • Blog as Guest
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

🚀 Cyber Monday Reloaded Price Drop! All in One Universal Bundle (3700+ Courses) @ 🎁 90% OFF - Ends in ENROLL NOW