octave: Processing Data in Cell Arrays
6.2.5 Processing Data in Cell Arrays
------------------------------------
Data that is stored in a cell array can be processed in several ways
depending on the actual data. The simplest way to process that data is
to iterate through it using one or more ‘for’ loops. The same idea can
be implemented more easily through the use of the ‘cellfun’ function
that calls a user-specified function on all elements of a cell array.
cellfun XREFcellfun.
An alternative is to convert the data to a different container, such
as a matrix or a data structure. Depending on the data this is possible
using the ‘cell2mat’ and ‘cell2struct’ functions.
-- : M = cell2mat (C)
Convert the cell array C into a matrix by concatenating all
elements of C into a hyperrectangle.
Elements of C must be numeric, logical, or char matrices; or cell
arrays; or structs; and ‘cat’ must be able to concatenate them
together.
DONTPRINTYET See also: mat2cell XREFmat2cell, *notenum2cell:
DONTPRINTYET See also: mat2cell XREFmat2cell, num2cell
XREFnum2cell.
-- : cell2struct (CELL, FIELDS)
-- : cell2struct (CELL, FIELDS, DIM)
Convert CELL to a structure.
The number of fields in FIELDS must match the number of elements in
CELL along dimension DIM, that is ‘numel (FIELDS) == size (CELL,
DIM)’. If DIM is omitted, a value of 1 is assumed.
A = cell2struct ({"Peter", "Hannah", "Robert";
185, 170, 168},
{"Name","Height"}, 1);
A(1)
⇒
{
Name = Peter
Height = 185
}
DONTPRINTYET See also: struct2cell XREFstruct2cell, *notecell2mat:
DONTPRINTYET See also: struct2cell XREFstruct2cell, cell2mat
XREFcell2mat, struct XREFstruct.