Aggregate Operations¶
Operations in this section should accept symbolic inputs on any type supported by the method.
all¶
Syntax
all(x)
all(x,dim)
Description
Returns an array of logical values indicating whether elements in
array, x, along a particular dimension, dim, are all nonzero.
For example, all(x,2) returns a column vector of logical values
indicating whether the elements of each row of x are all
nonzero. If dim is not specified, all will test the elements
along the first array dimension of x whose size does not equal 1.
any¶
Syntax
any(x)
any(x,dim)
Description
Returns an array of logical values indicating whether there is at
least one element in array, x, along a particular dimension,
dim, that is nonzero.
For example, any(x,2) returns a column vector of logical values
indicating whether there is at least one nonzero element in each row
of x. If dim is not specified, any will test the elements
along the first array dimension of x whose size does not equal 1.
arrayfun¶
Syntax
[r1,…,rm] = arrayfun(fHandle, a1,…,an)
[r1,…,rm] = arrayfun(fHandle, a1,…,an,'UniformOutput',value)
Description
This operation applies a function, specified by the function handle
fHandle, to each element of an array. The elements from arrays
a1,…,an are passed as input to fHandle and n is the
number of parameters that the function expects. Returns arrays
r1,…,rm where m is the number of outputs from fHandle.
- The input,
a1,..,an, must be arrays of the same size. - By default,
arrayfunassumes that output from thefHandlefunction has the same type and size. This is equivalent to invokingarrayfun(fHandle, a1,..,an,'UniformOutput',true). When thefHandlefunction returns output of differing sizes or types, indicate this by adding the parameters'UniformOutput'andfalseforvalue.
cellfun¶
Syntax
[r1,…,rm] = cellfun(fHandle, c1,…,cn)
[r1,…,rm] = cellfun(fHandle, c1,…,cn,'UniformOutput',value)
Description
This operation applies a function, specified by the function handle
fHandle, to each cell in a cell array. The elements from cell
arrays c1,…,cn are passed as input to fHandle and n is
the number of parameters that the function expects. Returns arrays
r1,…,rm where m is the number of outputs from fHandle.
- The input,
c1,..,cn, must be cell arrays of the same size. - By default,
cellfunassumes that output from thefHandlefunction has the same type and size. This is equivalent to invokingcellfun(fHandle, c1,..,cn,'UniformOutput',true). When thefHandlefunction returns output of differing sizes or types, indicate this by adding the parameters'UniformOutput'andfalseforvalue.
dot¶
Syntax
dot(x,y)
Description
Perform the scalar dot product of vectors, x and y. The length
of x and y must agree. If n is the length of the input
vectors, then dot(x,y)=x1*y1+x2*y2+…+xn*yn.
max¶
Syntax
m = max(x)
m = max(x,y)
m = max(x,[],dim)
[m, i] = max(x)
[m, i] = max(x,[],dim)
Description
There are multiple ways in which this function can be invoked. In all
cases, max identifies the largest elements of one or two arrays.
- When called with,
m = max(x), andxis a vector, thenmaxreturns the largest element inx.xis multidimensional array, this returns the largest element along the first dimension ofxwhose size does not equal 1. For example, ifxis a matrix, thenmis a row vector containing the maximum value in each column ofx.
- If invoked with
m = max(x,y),maxreturns the largest values in operandxandyelementwise. If bothxandyare arrays, their dimensions must agree. If either input is a scalar, it gets expanded into an appropriately sized array before finding the maximum. - When called with,
m=max(x,[],dim), thenmaxreturns the largest elements along thedimdimension ofx. - In addition to identifying the largest values of an input array,
when called with two output arguments,
[m, i] = max(…), this function records the indices of the maximum values ofxand returns them in output vectori. If the maximum occurs more than once, the index of the first occurance is returned.
min¶
Syntax
m = min(x)
m = min(x,y)
m = min(x,[],dim)
[m, i] = min(x)
[m, i] = min(x,[],dim)
Description
There are multiple ways in which this function can be invoked. In all
cases, min identifies the smallest elements of one or two arrays.
- When called with,
m = min(x), andxis a vector, thenminreturns the smallest element inx.xis multidimensional array, this returns the smallest element along the first dimension ofxwhose size does not equal 1. For example, ifxis a matrix, thenmis a row vector containing the minimum value in each column ofx.
- If invoked with
m = min(x,y),minreturns the smallest values in operandxandyelementwise. If bothxandyare arrays, their dimensions must agree. If either input is a scalar, it gets expanded into an appropriately sized array before finding the minimum. - When called with,
m=min(x,[],dim), thenminreturns the smallest elements along thedimdimension ofx. - In addition to identifying the smallest values of an input array,
when called with two output arguments,
[m, i] = min(…), this function records the indices of the minimum values ofxand returns them in output vectori. If the minimum occurs more than once, the index of the first occurance is returned.
sum¶
Syntax
sum(x)
sum(x,dim)
Description
Adds elements in array x along a particular dimension, dim.
If dim is not specified, this computes the sum along the first
array dimension whose size does not equal 1. For example, sum(x,1)
returns a row vector containing the sum of elements in each of the
columns of x.