8. Data Types
In this lesson you will learn:
- Data types in MATLAB.
- Data types Conversion.
- Determination of Data Types.
MATLAB does not require any type declaration or dimension statements. Whenever MATLAB encounters a new variable name, it creates the variable and allocates appropriate memory space. If the variable already exists, then MATLAB replaces the original content with new content and allocates new storage space, where necessary. For example, Total = 42
The above statement creates a 1-by-1 matrix named ‘Total’ and stores the value 42 in it.
1. Data Types Available in MATLAB:
MATLAB provides 15 fundamental data types. Every data type stores data that is in the form of a matrix or array. The size of this matrix or array is a minimum of 0-by-0 and this can grow up to a matrix or array of any size.
The following table shows the most commonly used data types in MATLAB:
int8 | 8-bit signed integer |
uint8 | 8-bit unsigned integer |
int16 | 16-bit signed integer |
uint16 | 16-bit unsigned integer |
int32 | 32-bit signed integer |
uint32 | 32-bit unsigned integer |
int64 | 64-bit signed integer |
uint64 | 64-bit unsigned integer |
single | single precision numerical data |
double | double precision numerical data |
logical | logical values of 1 or 0, represent true and false respectively |
char | character data (strings are stored as vector of characters) |
cell array | array of indexed cells, each capable of storing an array of a different dimension and data type |
structure | C-like structures, each structure having named fields capable of storing an array of a different dimension and data type |
user classes | objects constructed from a user-defined class |
java classes | objects constructed from a Java class |
function handle | pointer to a function |
Example:
Write the following code in script file
str = 'Hello World!' n = 2345 d = double(n) un = uint32(789.50) rn = 5678.92347 c = int32(rn)
and see what will you will get
2. Data Types Conversions in MATLAB:
MATLAB provides various functions for converting from one data type to another. Some of data types are shown in figure below.
For more visit the link below
http://www.mathworks.com/help/matlab/data-type-conversion.html