Range of values
X is a vector, then
range(X) is the range of the values in
X is a matrix, then
range(X) is a row vector containing the range of
each column in
X is a multidimensional array, then
range operates along the first nonsingleton
X, treating the values as vectors. The
size of this dimension becomes 1 while the sizes of all other dimensions
remain the same. If
X is an empty array with first
dimension 0, then
range(X) returns an empty array
with the same size as
Generate five large samples of standard normal random numbers.
rng('default') % For reproducibility rv = normrnd(0,1,1000,5);
Find the range values of the samples.
near6 = range(rv)
near6 = 1×5 6.8104 6.6420 6.9578 6.0860 6.8165
The range value is approximately 6 for each sample.
Find the range of exam scores over the course of five exams.
examgrades data set.
Find the range of all exam scores.
y = range(grades,'all')
y = 46
Find the range of exam scores for each student over the course of five exams.
examgrades data set.
Find the range of exam scores for the first 10 students. For example, the difference between the eighth student's best and worst exam scores is 7 points.
X = grades(1:10,:); y = range(X,2)
y = 10×1 12 13 10 12 8 16 14 7 12 10
Find the range of a multidimensional array over multiple dimensions.
Create a 3-by-5-by-2 array of normal random numbers with mean
mu = 2 and standard deviation
sigma = 7.
rng('default') % For reproducibility mu = 2; sigma = 7; X = normrnd(mu,sigma,[3 5 2])
X = X(:,:,1) = 5.7637 8.0352 -1.0351 21.3861 7.0778 14.8372 4.2314 4.3984 -7.4492 1.5586 -13.8119 -7.1538 27.0488 23.2445 7.0032 X(:,:,2) = 0.5652 11.8632 -6.4524 5.4223 -0.1241 1.1310 11.9203 7.0207 9.2429 4.0571 12.4279 6.7005 13.4116 7.0882 -3.5110
Find the range of each page of
X by specifying dimensions 1 and 2 as the operating dimensions.
ypage = range(X,[1 2])
ypage = ypage(:,:,1) = 40.8607 ypage(:,:,2) = 19.8641
ypage(1,1,2) is the range of all the elements in
Find the range of the elements in each
X(i,:,:) slice by specifying dimensions 2 and 3 as the operating dimensions.
yrow = range(X,[2 3])
yrow = 3×1 27.8385 22.2864 40.8607
yrow(3) is the range of all the elements in
X— Data sample
Data sample, specified as a scalar, vector, matrix, or multidimensional array.
X is a scalar, then
range(X) is 0.
X is a 0-by-0 empty array, then
range(X) is also an empty array.
dim— Dimension to operate along
Dimension to operate along, specified as a positive integer scalar. If you do not specify a value, then the default value is the first array dimension whose size does not equal 1.
dim indicates the dimension whose length reduces to
size(y,dim) is 1, while the sizes of all other
dimensions remain the same unless
size(X,dim) is 0. If
size(X,dim) is 0, then
range(X,dim) returns an empty array of the same size
Consider a two-dimensional data sample
dim is equal to 1, then
range(X,1) returns a row vector containing
the range for each column.
dim is equal to 2, then
range(X,2) returns a column vector containing
the range for each row.
dim is greater than
range returns an array of zeros with the same
dimensions and missing values as
vecdim— Vector of dimensions
Vector of dimensions, specified as a positive integer vector. Each element
vecdim represents a dimension of the input array
X. The output
y has length 1
in the specified operating dimensions. The other dimension lengths are the
For example, if
X is a 2-by-3-by-3 array, then
range(X,[1 2]) returns a 1-by-1-by-3 array. Each
element of the output array is the range of the elements on the
corresponding page of
y— Difference between maximum and minimum values
Difference between the maximum and minimum values, returned as a scalar, vector, matrix, or multidimensional array.
NaNs as missing values
and ignores them.
range provides an easily calculated estimate of the
spread of a sample. Avoid using
range with data that has
outliers because they have an undue influence on this statistic.
This function fully supports tall arrays. For more information, see Tall Arrays (MATLAB).
Usage notes and limitations:
vecdim input arguments are not supported.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).