Description |
CELL2VEC - Concatenate cell elements to a vector
The elements of arrays, which are elements of the input cell, are concatenated to a vector.
V = Cell2Vec(C)
INPUT:
C: Cell array of any size. Accepted classes: all numerical types
(DOUBLE, SINGLE, (U)INT8/16/32/64), LOGICAL, CHAR.
All non-empty cell elements must be the same class.
OUTPUT:
V: [1 x N] vector of all elements. The class of V is the class of the
cell elements of C.
EXAMPLE:
C = {1, 2; 3, 4};
V = Cell2Vec(C) % [1, 3, 2, 4] columnwise order
M = reshape(V, size(C)) % [1, 2; 3, 4]
NOTE: If the cell elements are vectors, this equals CAT, but is remarkably
faster for large cells: It seems that CAT fails for a smart pre-allocation?!
E.g. for a {1 x 5000} cell string with a total of 200.000 CHARs:
CAT (Matlab 6.5) => 60 sec
CAT (Matlab 7.8) => 5 sec
Cell2Vec: => 1.2 sec (1.5GHz Pentium-M).
Pre-compiled Mex-files: http://www.n-simon.de/mex
Run the unit-test uTest_Cell2Vec after compiling.
Tested: Matlab 6.5, 7.7, 7.8, WinXP, 32bit
Compiler: LCC2.4/3.8, BCC5.5, OWC1.8, MSVC2008
Assumed Compatibility: higher Matlab versions, Mac, Linux, 64bit
See also: CStr2String, CELL2MAT. |