Absolute value.
x = abs(z)
abs takes the absolute value of each element of its argument. The result is an array of the same size as the argument; each element is non-negative.
abs([2,-3,0,3+4j] 2 3 0 5
angle, sign, real, imag, hypot
Arc cosine.
y = acos(x)
acos(x) gives the arc cosine of x, which is complex if x is complex or if abs(x)>1.
acos(2) 0+1.3170j acos([0,1+2j]) 1.5708 1.1437-1.5286j
Inverse hyperbolic cosine.
y = acosh(x)
acosh(x) gives the inverse hyperbolic cosine of x, which is complex if x is complex or if x<1.
acosh(2) 1.3170 acosh([0,1+2j]) 0+1.5708j 1.5286+1.1437j
Inverse cotangent.
y = acot(x)
acot(x) gives the inverse cotangent of x, which is complex if x is.
Inverse hyperbolic cotangent.
y = acoth(x)
acoth(x) gives the inverse hyperbolic cotangent of x, which is complex if x is complex or is in the range (-1,1).
Inverse cosecant.
y = acsc(x)
acsc(x) gives the inverse cosecant of x, which is complex if x is complex or is in the range (-1,1).
Inverse hyperbolic cosecant.
y = acsch(x)
acsch(x) gives the inverse hyperbolic cosecant of x, which is complex if x is.
Phase angle of a complex number.
phi = angle(z)
angle(z) gives the phase of the complex number z, i.e. the angle between the positive real axis and a line joining the origin to z. angle(0) is 0.
angle(1+3j) 1.2490 angle([0,1,-1]) 0 0 3.1416
Inverse secant.
y = asec(x)
asec(x) gives the inverse secant of x, which is complex if x is complex or is in the range (-1,1).
Inverse hyperbolic secant.
y = asech(x)
asech(x) gives the inverse hyperbolic secant of x, which is complex if x is complex or strictly negative.
Arc sine.
y = asin(x)
asin(x) gives the arc sine of x, which is complex if x is complex or if abs(x)>1.
asin(0.5) 0.5236 asin(2) 1.5708-1.317j
Inverse hyperbolic sine.
y = asinh(x)
asinh(x) gives the inverse hyperbolic sine of x, which is complex if x is complex.
asinh(2) 1.4436 asinh([0,1+2j]) 0 1.8055+1.7359j
Arc tangent.
y = atan(x)
atan(x) gives the arc tangent of x, which is complex if x is complex.
atan(1) 0.7854
Direction of a point given by its Cartesian coordinates.
phi = atan2(y,x)
atan2(y,x) gives the direction of a point given by its Cartesian coordinates x and y. Imaginary component of complex numbers is ignored. atan2(y,x) is equivalent to atan(y/x) if x>0.
atan2(1, 1) 0.7854 atan2(-1, -1) -2.3562 atan2(0, 0) 0
Inverse hyperbolic tangent.
y = atanh(x)
atan(x) gives the inverse hyperbolic tangent of x, which is complex if x is complex or if abs(x)>1.
atanh(0.5) 0.5493 atanh(2) 0.5493 + 1.5708j
Beta function.
y = beta(z,w)
beta(z,w) gives the beta function of z and w. Arguments and result are real (imaginary part is discarded). The beta function is defined as
beta(1,2) 0.5
Incomplete beta function.
y = betainc(x,z,w)
betainc(x,z,w) gives the incomplete beta function of x, z and w. Arguments and result are real (imaginary part is discarded). x must be between 0 and 1. The incomplete beta function is defined as
betainc(0.2,1,2) 0.36
Logarithm of beta function.
y = betaln(z,w)
betaln(z,w) gives the logarithm of the beta function of z and w. Arguments and result are real (imaginary part is discarded).
betaln(0.5,2) 0.2877
Type conversion.
Y = cast(X, type)
cast(X,type) converts the numeric array X to the type given by string type, which can be 'double', 'single', 'int8' or any other signed or unsigned integer type, 'char', or 'logical'. The number value is preserved when possible; conversion to integer types discards most significant bytes. If X is an array, conversion is performed on each element; the result has the same size. The imaginary part, if any, is discarded only with conversions to integer types.
cast(pi, 'int8') 3int8
uint8 and related functions, double, single, typecast
Cumulative distribution function.
y = cdf(distribution,x) y = cdf(distribution,x,a1) y = cdf(distribution,x,a1,a2)
cdf(distribution,x) calculates the integral of a probability density function from
Distribution | Name | Parameters |
---|---|---|
Beta | beta | a and b |
Cauchy | cauchy | a and b |
chi | deg. of freedom |
|
chi2 chisquare |
deg. of freedom |
|
gamma | shape |
|
exponential | exp exponential |
mean |
F | f | deg. of freedom |
half-normal | half-normal | |
Laplace | laplace | mean and scale |
lognormal | logn lognormal |
mean (0) and st. dev. (1) |
normal | norm normal |
mean (0) and st. dev. (1) |
Rayleigh | rayl rayleigh |
b |
Student's T | t student |
deg. of freedom |
uniform | unif uniform |
limits of the range (0 and 1) |
Weibull | weib weibull |
a and b |
Rounding towards +infinity.
y = ceil(x)
ceil(x) gives the smallest integer larger than or equal to x. If the argument is a complex number, the real and imaginary parts are handled separately.
ceil(2.3) 3 ceil(-2.3) -2 ceil(2.3-4.5j) 3-4j
Make a complex number.
z = complex(x, y)
complex(x,y) makes a complex number from its real part x and imaginary part y. The imaginary part of its input arguments is ignored.
complex(2, 3) 2 + 3j complex(1:5, 2) 1+2j 2+2j 3+2j 4+2j 5+2j
Complex conjugate value.
w = conj(z)
conj(z) changes the sign of the imaginary part of the complex number z.
conj([1+2j,-3-5j,4,0]) 1-2j -3+5j 4 0
imag, angle, j, operator -
Cosine.
y = cos(x)
cos(x) gives the cosine of x, which is complex if x is complex.
cos([0, 1+2j]) 1 2.0327-3.0519j
Hyperbolic cosine.
y = cosh(x)
cos(x) gives the hyperbolic cosine of x, which is complex if x is complex.
cosh([0, 1+2j]) 1 -0.6421+1.0686j
Cotangent.
y = cot(x)
cot(x) gives the cotangent of x, which is complex if x is.
Hyperbolic cotangent.
y = coth(x)
coth(x) gives the hyperbolic cotangent of x, which is complex if x is.
Cosecant.
y = csc(x)
csc(x) gives the cosecant of x, which is complex if x is.
Hyperbolic cosecant.
y = csch(x)
csch(x) gives the hyperbolic cosecant of x, which is complex if x is.
Dilogarithm.
y = diln(x)
diln(x) gives the dilogarithm, or Spence's integral, of x. Argument and result are real (imaginary part is discarded). The dilogarithm is defined as
diln([0.2, 0.7, 10]) -1.0748 -0.3261 3.9507
Conversion to double-precision numbers.
B = double(A)
double(A) converts number or array A to double precision. A can be any kind of numeric value (real, complex, or integer), or a character or logical array.
To keep the integer type of logical and character arrays, the unitary operator + should be used instead.
double(uint8(3)) 3 double('AB') 65 66 islogical(double(1>2)) false
uint8 and related functions, single, cast, operator +, setstr, char, logical
Jacobi elliptic amplitude.
phi = ellipam(u, m) phi = ellipam(u, m, tol)
ellipam(u,m) gives the Jacobi elliptic amplitude phi.
Parameter m must be in [0,1]. The Jacobi elliptic amplitude is the
inverse of the Jacobi integral of the first kind, such that
ellipam(u,m,tol) uses tolerance tol; the default tolerance is eps.
phi = ellipam(2.7, 0.6) phi = 2.0713 u = ellipf(phi, 0.6) u = 2.7
Jacobi elliptic integral of the second kind.
u = ellipe(phi, m)
ellipe(phi,m) gives the Jacobi elliptic integral of the second kind, defined as
Complete elliptic integrals of first and second kinds, with phi=pi/2, can be obtained with ellipke.
Jacobi elliptic integral of the first kind.
u = ellipf(phi, m)
ellipf(phi,m) gives the Jacobi elliptic integral of the first kind, defined as
Complete elliptic integrals of first and second kinds, with phi=pi/2, can be obtained with ellipke.
Jacobi elliptic functions.
(sn, cn, dn) = ellipj(u, m) (sn, cn, dn) = ellipj(u, m, tol)
ellipj(u,m) gives the Jacobi elliptic function sn, cn, and dn.
Parameter m must be in [0,1]. These functions are based on the
Jacobi elliptic amplitude
ellipj(u,m,tol) uses tolerance tol; the default tolerance is eps.
(sn, cn, dn) = ellipj(2.7, 0.6) sn = 0.8773 cn = -0.4799 dn = 0.7336 sin(ellipam(2.7, 0.6)) 0.8773 ellipj(0:5, 0.3) 0.0000 0.8188 0.9713 0.4114 -0.5341 -0.9930
Complete elliptic integral.
(K, E) = ellipke(m) (K, E) = ellipke(m, tol)
(K,E)=ellipke(m) gives the complete elliptic integrals of the first kind K=F(m) and second kind E=E(m), defined as
Parameter m must be in [0,1].
ellipke(m,tol) uses tolerance tol; the default tolerance is eps.
(K, E) = ellipke(0.3) K = 1.7139 E = 1.4454
Difference between 1 and the smallest number x such that x > 1.
e = eps e = eps(x) e = eps(type)
Because of the floating-point encoding of "real" numbers, the absolute precision depends on the magnitude of the numbers. The relative precision is characterized by the number given by eps, which is the smallest double positive number such that 1+eps can be distinguished from 1.
eps(x) gives the smallest number e such that x+e has the same sign as x and can be distinguished from x. It takes into account whether x is a double or a single number. If x is an array, the result has the same size; each element corresponds to an element of the input.
eps('single') gives the smallest single positive number e such that 1single+e can be distinguished from 1single. eps('double') gives the same value as eps without input argument.
eps 2.2204e-16 1 + eps - 1 2.2204e-16 eps / 2 1.1102e-16 1 + eps / 2 - 1 0
Error function.
y = erf(x)
erf(x) gives the error function of x. Argument and result are real (imaginary part is discarded). The error function is defined as
erf(1) 0.8427
Complementary error function.
y = erfc(x)
erfc(x) gives the complementary error function of x. Argument and result are real (imaginary part is discarded). The complementary error function is defined as
erfc(1) 0.1573
Inverse error function.
x = erfinv(y)
erfinv(y) gives the value x such that y=erf(x). Argument and result are real (imaginary part is discarded). y must be in the range [-1,1]; values outside this range give nan.
y = erf(0.8) y = 0.7421 erfinv(y) 0.8
Exponential.
y = exp(x)
exp(x) is the exponential of x, i.e. 2.7182818284590446...^x.
exp([0,1,0.5j*pi]) 1 2.7183 1j
log, expm1, expm, operator .^
Exponential minus one.
y = expm1(x)
expm1(x) is exp(x)-1 with improved precision for small x.
expm1(1e-15) 1e-15 exp(1e-15)-1 1.1102e-15
Factorial.
y = factorial(n)
factorial(n) gives the factorial n! of nonnegative integer n. If the input argument is negative or noninteger, the result is NaN. The imaginary part is ignored.
factorial(5) 120 factorial([-1,0,1,2,3,3.14]) nan 1 1 2 6 nan
Rounding towards 0.
y = fix(x)
fix(x) truncates the fractional part of x. If the argument is a complex number, the real and imaginary parts are handled separately.
fix(2.3) 2 fix(-2.6) -2
Rounding towards -infinity.
y = floor(x)
floor(x) gives the largest integer smaller than or equal to x. If the argument is a complex number, the real and imaginary parts are handled separately.
floor(2.3) 2 floor(-2.3) -3
Gamma function.
y = gamma(x)
gamma(x) gives the gamma function of x. Argument and result are real (imaginary part is discarded). The gamma function is defined as
For positive integer values,
gamma(5) 24 gamma(-3) inf gamma(-3.5) 0.2701
beta, gammaln, gammainc, factorial
Incomplete gamma function.
y = gammainc(x,a)
gammainc(x,a) gives the incomplete gamma function of x and a. Arguments and result are real (imaginary part is discarded). x must be nonnegative. The incomplete gamma function is defined as
gammainc(2,1.5) 0.7385
Logarithm of gamma function.
y = gammaln(x)
gammaln(x) gives the logarithm of the gamma function of x. Argument and result are real (imaginary part is discarded). gammaln does not rely on the computation of the gamma function to avoid overflows for large numbers.
gammaln(1000) 5905.2204 gamma(1000) inf
Greatest common divisor.
q = gcd(a, b)
gcd(a,b) gives the greatest common divisor of integer numbers a and b.
gcd(72, 56) 8
Golden ratio constant.
x = goldenratio
goldenratio is the golden ration
goldenratio 1.6180
Hypotenuse.
c = hypot(a, b)
hypot(a,b) gives the square root of the square of a and b, or of their absolute value if they are complex. The result is always real. hypot avoids overflow when the result itself does not overflow.
hypot(3, 4) 5 hypot([1,2,3+4j,inf], 5) 5.099 5.3852 5.831 inf
Imaginary unit.
i j 1.23e4i 1.23e4j
i or j are the imaginary unit, i.e. the pure imaginary number whose square is -1. i and j are equivalent.
Used as a suffix appended without space to a number, i or j mark an imaginary number. They must follow the fractional part and the exponent, if any; for single-precision numbers, they must precede the single suffix.
To obtain a complex number i, you can write either i or 1i (or j or 1j). The second way is safer, because variables i and j are often used as indices and would hide the meaning of the built-in functions. The expression 1i is always interpreted as an imaginary constant number.
Imaginary numbers are displayed with i or j depending on the option set with the format command.
i 1j format i 2i 2i 2single + 5jsingle 2+5i (single)
Inverse cumulative distribution function.
x = icdf(distribution,p) x = icdf(distribution,p,a1) x = icdf(distribution,p,a1,a2)
icdf(distribution,p) calculates the value of x such that cdf(distribution,x) is p. The distribution is specified with the first argument, a string; case is ignored ('t' and 'T' are equivalent). Additional arguments must be provided for some distributions. The distributions are given in the table below. Default values for the parameters, when mentioned, mean that the parameter may be omitted.
Distribution | Name | Parameters |
---|---|---|
Beta | beta | a and b |
chi2 chisquare |
deg. of freedom |
|
gamma | shape |
|
F | f | deg. of freedom |
lognormal | logn lognormal |
mean (0) and st. dev. (1) |
normal | norm normal |
mean (0) and st. dev. (1) |
Student's T | t student |
deg. of freedom |
uniform | unif uniform |
limits of the range (0 and 1) |
Imaginary part of a complex number.
im = imag(z)
imag(z) is the imaginary part of the complex number z, or 0 if z is real.
imag(1+2j) 2 imag(1) 0
Infinity.
x = inf x = Inf x = inf(n) x = inf(n1,n2,...) x = inf([n1,n2,...]) x = inf(..., type)
inf is the number which represents infinity. Most mathematical functions accept infinity as input argument and yield an infinite result if appropriate. Infinity and minus infinity are two different quantities.
With integer non-negative arguments, inf creates arrays whose elements are infinity. Arguments are interpreted the same way as zeros and ones.
The last argument of inf can be a string to specify the type of the result: 'double' for double-precision (default), or 'single' for single-precision.
1/inf 0 -inf -inf
isfinite, isinf, nan, zeros, ones
Test for finiteness.
b = isfinite(x)
isfinite(x) is true if the input argument is a finite number (neither infinite nor nan), and false otherwise. The result is performed on each element of the input argument, and the result has the same size.
isfinite([0,1,nan,inf]) T T F F
Test for a floating-point object.
b = isfloat(x)
isfloat(x) is true if the input argument is a floating-point type (double or single), and false otherwise.
isfloat(2) true isfloat(2int32) false
Test for infinity.
b = isinf(x)
isinf(x) is true if the input argument is infinite (neither finite nor nan), and false otherwise. The result is performed on each element of the input argument, and the result has the same size.
isinf([0,1,nan,inf]) F F F T
Test for an integer object.
b = isinteger(x)
isinteger(x) is true if the input argument is an integer type (including char and logical), and false otherwise.
isinteger(2int16) true isinteger(false) true isinteger('abc') true isinteger(3) false
Test for Not a Number.
b = isnan(x)
isnan(x) is true if the input argument is nan (not a number), and false otherwise. The result is performed on each element of the input argument, and the result has the same size.
isnan([0,1,nan,inf]) F F T F
Test for a numeric object.
b = isnumeric(x)
isnumeric(x) is true if the input argument is numeric (real or complex scalar, vector, or array), and false otherwise.
isnumeric(pi) true isnumeric('abc') false
ischar, isfloat, isinteger, isscalar, isvector
Test for a scalar number.
b = isscalar(x)
isscalar(x) is true if the input argument is scalar (real or complex number of any floating-point or integer type, character or logical value), and false otherwise.
isscalar(2) true isscalar([1, 2, 5]) false
Test for a vector.
b = isvector(x)
isvector(x) is true if the input argument is a row or column vector (real or complex 2-dimension array of any floating-point or integer type, character or logical value with one dimension equal to 1, or empty array), and false otherwise.
isvector([1, 2, 3]) true isvector([1; 2]) true isvector(7) true isvector([1, 2; 3, 4]) false
isnumeric, isscalar, size, ndims, length
Least common multiple.
q = lcm(a, b)
lcm(a,b) gives the least common multiple of integer numbers a and b.
lcm(72, 56) 504
Natural (base e) logarithm.
y = log(x)
log(x) gives the natural logarithm of x. It is the inverse of exp. The result is complex if x is not real positive.
log([-1,0,1,10,1+2j]) 0+3.1416j inf 0 2.3026 0.8047+1.1071j
log10, log2, log1p, reallog, exp
Decimal logarithm.
y = log10(x)
log10(x) gives the decimal logarithm of x, defined by log10(x) = log(x)/log(10). The result is complex if x is not real positive.
log10([-1,0,1,10,1+2j]) 0+1.3644j inf 0 1 0.3495+0.4808j
Logarithm of x plus one.
y = log1p(x)
log1p(x) is log(1+x) with improved precision for small x.
log1p(1e-15) 1e-15 log(1 + 1e-15) 1.1102e-15
Base 2 logarithm.
y = log2(x)
log2(x) gives the base 2 logarithm of x, defined as log2(x)=log(x)/log(2). The result is complex if x is not real positive.
log2([1, 2, 1024, 2000, -5]) 0 1 10 10.9658 2.3219+4.5324j
Modulo.
m = mod(x, y)
mod(x,y) gives the modulo of x divided by y, i.e. a number m between 0 and y such that x = q*y+m with integer q. Imaginary parts, if they exist, are ignored.
mod(10,7) 3 mod(-10,7) 4 mod(10,-7) -4 mod(-10,-7) -3
Not a Number.
x = nan x = NaN x = nan(n) x = nan(n1,n2,...) x = nan([n1,n2,...]) x = nan(..., type)
NaN (Not a Number) is the result of the primitive floating-point functions or operators called with invalid arguments. For example, 0/0, inf-inf and 0*inf all result in NaN. When used in an expression, NaN propagates to the result. All comparisons involving NaN result in false, except for comparing NaN with any number for inequality, which results in true.
Contrary to built-in functions usually found in the underlying operating system, many functions which would result in NaNs give complex numbers when called with arguments in a certain range.
With integer non-negative arguments, nan creates arrays whose elements are NaN. Arguments are interpreted the same way as zeros and ones.
The last argument of nan can be a string to specify the type of the result: 'double' for double-precision (default), or 'single' for single-precision.
nan nan 0*nan nan nan==nan false nan~=nan true log(-1) 0+3.1416j
Binomial coefficient.
b = nchoosek(n, k)
nchoosek(n,k) gives the number of combinations of n objects taken k at a time. Both n and k must be nonnegative integers with k<n.
nchoosek(10,4) 210 nchoosek(10,6) 210
Probability density function.
y = pdf(distribution,x) y = pdf(distribution,x,a1) y = pdf(distribution,x,a1,a2)
pdf(distribution,x) gives the probability of a density function. The distribution is specified with the first argument, a string; case is ignored ('t' and 'T' are equivalent). Additional arguments must be provided for some distributions. See cdf for the list of distributions.
Constant
x = pi
pi is the number
exp(1j * pi) -1
goldenratio, i, j, eps
Real part of a complex number.
re = real(z)
real(z) is the real part of the complex number z, or z if z is real.
real(1+2j) 1 real(1) 1
Real natural (base e) logarithm.
y = reallog(x)
reallog(x) gives the real natural logarithm of x. It is the inverse of exp for real numbers. The imaginary part of x is ignored. The result is NaN if x is negative.
reallog([-1,0,1,10,1+2j]) nan inf 0 2.3026 0
Largest and smallest real numbers.
x = realmax x = realmax(n) x = realmax(n1,n2,...) x = realmax([n1,n2,...]) x = realmax(..., type) x = realmin x = realmin(...)
realmax gives the largest positive real number in double precision. realmin gives the smallest positive real number in double precision which can be represented in normalized form (i.e. with full mantissa precision).
With integer non-negative arguments, realmax and realmin create arrays whose elements are all set to the respective value. Arguments are interpreted the same way as zeros and ones.
The last argument of realmax and realmin can be a string to specify the type of the result: 'double' for double-precision (default), or 'single' for single-precision.
realmin 2.2251e-308 realmin('single') 1.1755e-38 realmax 1.7977e308 realmax('single') 3.4028e38single realmax + eps(realmax) inf
Real power.
z = realpow(x, y)
realpow(x,y) gives the real value of x to the power y. The imaginary parts of x and y are ignored. The result is NaN if it is not defined for the input arguments. If the arguments are arrays, their size must match or one of them must be a scalar number; the power is performed element-wise.
operator .^, reallog, realsqrt
Real square root.
y = realsqrt(x)
realsqrt(x) gives the real square root of x. The imaginary part of x is ignored. The result is NaN if x is negative.
realsqrt([-1,0,1,10,1+2j]) nan 0 1 3.1623 1
Remainder of a real division.
r = rem(x, y)
rem(x,y) gives the remainder of x divided by y, i.e. a number r between 0 and sign(x)*abs(y) such that x = q*y+r with integer q. Imaginary parts, if they exist, are ignored.
rem(10,7) 3 rem(-10,7) -3 rem(10,-7) 3 rem(-10,-7) -3
Rounding to the nearest integer.
y = round(x)
round(x) gives the integer nearest to x. If the argument is a complex number, the real and imaginary parts are handled separately.
round(2.3) 2 round(2.6) 3 round(-2.3) -2
Sign of a real number or direction of a complex number.
s = sign(x) z2 = sign(z1)
With a real argument, sign(x) is 1 if x>0, 0 if x==0, or -1 if x<0. With a complex argument, sign(z1) is a complex value with the same phase as z1 and whose magnitude is 1.
sign(-2) -1 sign(1+1j) 0.7071+0.7071j sign([0, 5]) 0 1
Secant.
y = sec(x)
sec(x) gives the secant of x, which is complex if x is.
Hyperbolic secant.
y = sech(x)
acot(x) gives the hyperbolic secant of x, which is complex if x is.
Sine.
y = sin(x)
sin(x) gives the sine of x, which is complex if x is complex.
sin(2) 0.9093
Sinc.
y = sinc(x)
sinc(x) gives the sinc of x, i.e. sin(pi*x)/(pi*x) if x~=0 or 1 if x==0. The result is complex if x is complex.
sinc(1.5) -0.2122
Conversion to single-precision numbers.
B = single(A)
single(A) converts number or array A to single precision. A can be any kind of numeric value (real, complex, or integer), or a character or logical array.
Single literal numbers can be entered as a floating-point number with the single suffix.
single(pi) 3.1416single single('AB') 1x2 single array 65 66 3.7e4single 37000single
double, uint8 and related functions, operator +, setstr, char, logical
Hyperbolic sine.
y = sinh(x)
sinh(x) gives the hyperbolic sine of x, which is complex if x is complex.
sinh(2) 3.6269
Square root.
r = sqrt(z)
sqrt(z) gives the square root of z, which is complex if z is not real positive.
sqrt(4) 2 sqrt([1 4 -9 3+4j]) 1 2 3j 2+1j
Conversion between big-endian and little-endian representation.
Y = swapbytes(X)
swapbytes(X) swaps the bytes representing number X. If X is an array, each number is swapped separately. The imaginary part, if any, is discarded. X can be of any numerical type. swapbytes is its own inverse for real numbers.
swapbytes(1uint32) 16777216uint32
Tangent.
y = tan(x)
tan(x) gives the tangent of x, which is complex if x is complex.
tan(2) -2.185
Hyperbolic tangent.
y = tanh(x)
tanh(x) gives the hyperbolic tangent of x, which is complex if x is complex.
tanh(2) 0.964
Type conversion with same binary representation.
Y = typecast(X, type)
typecast(X,type) changes the numeric array X to the type given by string type, which can be 'double', 'single', 'int8' or any other signed or unsigned integer type, 'char', or 'logical'. The binary representation in memory is preserved. The imaginary part, if any, is discarded. Depending on the conversion, the number of elements is changed, so that the array size in bytes in preserved. The result is a row vector if X is a scalar or a row vector, or a column vector otherwise. The result depends on the computer architecture.
typecast(1uint32, 'uint8') 1x4 uint8 array 0 0 0 1 typecast(pi, 'uint8') 1x8 uint8 array 64 9 33 251 84 68 45 24