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.

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)

you will get



Data Type Conversion:


MATLAB provides various functions for converting from one data type to another. The following table shows the data type conversion functions:




Determination of Data Types:


MATLAB provides various functions for identifying data type of a variable. Following table provides the functions for determining the data type of a variable:




Example:


Create a script file with the following code and check the result.


x = 3

isinteger(x)
isfloat(x)
isvector(x)
isscalar(x)
isnumeric(x)

x = 23.54
isinteger(x)
isfloat(x)
isvector(x)
isscalar(x)
isnumeric(x)

x = [1 2 3]
isinteger(x)
isfloat(x)
isvector(x)
isscalar(x)

x = 'Hello'
isinteger(x)
isfloat(x)
isvector(x)
isscalar(x)

isnumeric(x)