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, arrayfun assumes that output from the fHandle function has the same type and size. This is equivalent to invoking arrayfun(fHandle, a1,..,an,'UniformOutput',true). When the fHandle function returns output of differing sizes or types, indicate this by adding the parameters 'UniformOutput' and false for value.

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, cellfun assumes that output from the fHandle function has the same type and size. This is equivalent to invoking cellfun(fHandle, c1,..,cn,'UniformOutput',true). When the fHandle function returns output of differing sizes or types, indicate this by adding the parameters 'UniformOutput' and false for value.

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), and
    • x is a vector, then max returns the largest element in x.
    • x is multidimensional array, this returns the largest element along the first dimension of x whose size does not equal 1. For example, if x is a matrix, then m is a row vector containing the maximum value in each column of x.
  • If invoked with m = max(x,y), max returns the largest values in operand x and y elementwise. If both x and y are 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), then max returns the largest elements along the dim dimension of x.
  • 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 of x and returns them in output vector i. 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), and
    • x is a vector, then min returns the smallest element in x.
    • x is multidimensional array, this returns the smallest element along the first dimension of x whose size does not equal 1. For example, if x is a matrix, then m is a row vector containing the minimum value in each column of x.
  • If invoked with m = min(x,y), min returns the smallest values in operand x and y elementwise. If both x and y are 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), then min returns the smallest elements along the dim dimension of x.
  • 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 of x and returns them in output vector i. 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.