dmarrayfun
Apply function to each element in DataMatrix object
Syntax
DMObjNew1
=
dmarrayfun(Func
, DMObj1
)
DMObjNew1
=
dmarrayfun(Func
, DMObj1
, DMObj2
,
...)
[DMObjNew1
, DMObjNew2
,
...] = dmarrayfun(Func
, DMObj1
,
...)
[DMObjNew1
, ...]
= dmarrayfun(Func
, DMObj1
,
...'UniformOutput', UniformOutputValue
,
...)
[DMObjNew1
, ...] = dmarrayfun(Func
, DMObj1
,
...'DataMatrixOutput', DataMatrixOutputValue
,
...)
[DMObjNew1
, ...] = dmarrayfun(Func
, DMObj1
,
...'Rows', RowsValue
, ...)
[DMObjNew1
, ...] = dmarrayfun(Func
, DMObj1
,
...'Columns', ColumnsValue
, ...)
[DMObjNew1
, ...] = dmarrayfun(Func
, DMObj1
,
...'ErrorHandler', ErrorFuncHandle
, ...)
Input Arguments
Func | Function handle for a function that returns one or more scalars, and returns values of the same class each time it is called. |
DMObj1 | DataMatrix object, such as created by |
DMObj2 | Either of the following:
Note
|
UniformOutputValue | Specifies whether |
DataMatrixOutputValue | Specifies whether return values must be DataMatrix objects.
Choices are |
RowsValue , ColumnsValue | Specifies the rows or columns to which to apply the function. Choices are:
|
ErrorFuncHandle | Specifies a function handle to a function that dmarrayfun calls
if the call to Func fails. |
Output Arguments
DMObjNew1 , DMObjNew2 | DataMatrix objects created from applying the function to each
element in one or more DataMatrix objects. The size (number of rows
and columns), row names, and column names will be the same as DMObj1 . |
Description
applies
the function specified by DMObjNew1
=
dmarrayfun(Func
, DMObj1
)Func
to each
element in DMObj1
, a DataMatrix object,
and returns the results in DMObjNew1
, a
new DataMatrix object. DMObjNew1
has the
same size (number of rows and columns), row names, and column names
as DMObj1
. The I
,J
th
element of DMObjNew1
is equal to
,
where Func
(DMObj1
(I,J))Func
is a function handle for a function
that takes one input argument, returns one scalar value, and returns
values of the same class each time it is called.
evaluates the function specified by DMObjNew1
=
dmarrayfun(Func
, DMObj1
, DMObj2
,
...)Func
using
elements in DMObj1
, DMObj2
,
etc. as input arguments. The I
,J
th
element of DMObjNew1
is equal to
, where Func
(DMObj1
(I,J), DMObj2
(I,J),
...)Func
is a function
handle for a function that takes multiple input arguments, returns
one scalar, and returns values of the same class each time it is called.
[
evaluates the function specified by DMObjNew1
, DMObjNew2
,
...] = dmarrayfun(Func
, DMObj1
,
...)Func
using
elements in DMObj1
, and possibly other
input arguments. Func
is a function handle
for a function that takes one or more input arguments, returns multiple
scalars, and returns values of the same class each time it is called.
It returns DataMatrix objects DMObjNew1
, DMObjNew2
,
etc. with each one corresponding to one of the outputs of Func
.
The outputs of Func
may be of different
classes, however, but each output must be the same each time it is
called.
[
calls DMObjNew1
, ...] = dmarrayfun(Func
, DMObj1
,
...'PropertyName
', PropertyValue
,
...)dmarrayfun
with optional
properties that use property name/property value pairs. You can specify
one or more properties in any order. Each PropertyName
must
be enclosed in single quotation marks and is case insensitive. These
property name/property value pairs are as follows:
[
specifies whether DMObjNew1
, ...]
= dmarrayfun(Func
, DMObj1
,
...'UniformOutput', UniformOutputValue
,
...)Func
must
return output values without encapsulation in a cell array. Choices
are true
(default) or false
.
If true
, dmarrayfun
must return
scalar values that can be concatenated into an array. These values
can also be a cell array. If false
, dmarrayfun
returns
a cell array (or multiple cell arrays), where the I
,J
th
cell contains the value equal to
.Func
(DMObj1
(I,J),...)
[
specifies whether return values must be DataMatrix
objects. Choices are DMObjNew1
, ...] = dmarrayfun(Func
, DMObj1
,
...'DataMatrixOutput', DataMatrixOutputValue
,
...)true
(default) or false
.
If you set the 'UniformOutput'
property to false
,
this property is ignored.
[
applies
the function only to the rows in the DataMatrix object specified by DMObjNew1
, ...] = dmarrayfun(Func
, DMObj1
,
...'Rows', RowsValue
, ...)RowsValue
,
which can be a positive integer, vector of positive integers, character
vector specifying a row name, cell array of character vectors, or
a logical vector.
[
applies the function only to the columns in the DataMatrix object specified by
DMObjNew1
, ...] = dmarrayfun(Func
, DMObj1
,
...'Columns', ColumnsValue
, ...)ColumnsValue
, which can be a positive integer, vector of
positive integers, character vector specifying a column name, cell array of character
vectors, or a logical vector.
[
specifies a function handle to a function that DMObjNew1
, ...] = dmarrayfun(Func
, DMObj1
,
...'ErrorHandler', ErrorFuncHandle
, ...)dmarrayfun
calls if
the call to Func
fails. The error handling function will be
called with these input arguments:
Structure with the following fields:
identifier
— Identifier of the errormessage
— Error message textindex
— Linear index into the input array(s) at which the error occurred
Set of input arguments at which the call to the function failed
If you do not specify ErrorFuncHandle
,
dmarrayfun
rethrows the error from the call to
Func
.
Version History
Introduced in R2008b