MATLAB Function Reference Previous page   Next Page

Distribute inputs to outputs



[Y1, Y2, Y3, ...] = deal(X) copies the single input to all the requested outputs. It is the same as Y1 = X, Y2 = X, Y3 = X, ...

[Y1, Y2, Y3, ...] = deal(X1, X2, X3, ...) is the same as Y1 = X1;
Y2 = X2; Y3 = X3; ...


deal is most useful when used with cell arrays and structures via comma-separated list expansion. Here are some useful constructions:

[S.field] = deal(X) sets all the fields with the name field in the structure array S to the value X. If S doesn't exist, use [S(1:m).field] = deal(X).

[X{:}] = deal(A.field) copies the values of the field with name field to the cell array X. If X doesn't exist, use [X{1:m}] = deal(A.field).

[Y1, Y2, Y3, ...] = deal(X{:}) copies the contents of the cell array X to the separate variables Y1, Y2, Y3, ...

[Y1, Y2, Y3, ...] = deal(S.field) copies the contents of the fields with the name field to separate variables Y1, Y2, Y3, ...


Use deal to copy the contents of a 4-element cell array into four separate output variables.

Use deal to obtain the contents of all the name fields in a structure array:

These two commands perform the same operation as those used in the previous two examples, except that these commands do not require deal.

See Also

cell, iscell, celldisp, struct, isstruct, fieldnames, isfield, orderfields, rmfield, cell2struct, struct2cell

Previous page  ddeset deblank Next page

© 1994-2005 The MathWorks, Inc.