Matlab Data Types
Matlab 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.
The following table shows the most commonly used data types in MATLAB −
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
Example
Create a script file with the following code −
When the above code is compiled and executed, it produces the following result −
Function Purpose
mat2cell Convert array to cell array with potentially different sized cells
Following table provides the functions for determining the data type of a variable −
Function Purpose
is Detect state
Example
Create a script file with the following code −
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)
x = 3
ans = 0
ans = 1
ans = 1
ans = 1
ans = 1
x = 1177/50
ans = 0
ans = 1
ans = 1
ans = 1
ans = 1
x =
1 2 3
ans = 0
ans = 1
ans = 1
ans = 0
x = Hello
ans = 0
ans = 0
ans = 1
ans = 0
ans = 0
Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js