>> 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
|
|
uint8
|
|
int16
|
|
uint16
|
|
int32
|
|
uint32
|
|
int64
|
|
uint64
|
|
single
|
|
double
|
|
logical
|
|
char
|
character data (strings are stored as vector of characters)
|
cell array
|
|
structure
|
C-like structures, each structure having named fields capable of storing an array of a different dimension and data type
|
user classes
|
|
java classes
|
|
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)
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)
0Awesome Comments!