deal
Distribute inputs to outputs
Description
Note
In most cases, you do not need the deal
function. Instead, use
array indexing and comma-separated lists when accessing the contents of cell arrays and
structure fields, as shown in these syntaxes.
[A1,...,An] = C{:} [B1,...,Bn] = S(:).field
For more information, see Comma-Separated Lists.
However, in a few cases deal
can be useful when you need
multiple outputs from an operation that typically returns a single output. For example,
you can use deal
to:
Assign values to multiple cells of a cell array.
Assign values to a field of a nonscalar structure array.
Return multiple outputs from an anonymous function.
[
copies the input arguments B1,...,Bn
] = deal(A1,...,An
)A1,...,An
and returns them as the output
arguments B1,...,Bn
. It is the same as B1 = A1
, …,
Bn = An
. In this syntax, the numbers of input and output arguments must
be the same.
[
copies the single input
argument B1,...,Bn
] = deal(A)A
and returns it as the output arguments
B1,...,Bn
. It is the same as B1 = A
, …, Bn
= A
. In this syntax, you can specify an arbitrary number of output arguments.
Examples
Input Arguments
Output Arguments
Tips
To convert a cell array to a structure array, or a structure array to a cell array, use the
cell2struct
andstruct2cell
functions, notdeal
.
Extended Capabilities
Version History
Introduced before R2006a