File Exchange

image thumbnail


version (10.1 KB) by Jan
Concatenate cell elements to a vector - fast C-Mex


Updated 03 May 2015

View Version History

View License

CELL2VEC - Concatenate cell elements to a vector
V = Cell2Vec(C)
C: Cell array of any size and types:
The elements of C can have different sizes.
V: [1 x N] vector of all elements.

C = {1, 2; 3, 4};
V = Cell2Vec(C) % [1, 3, 2, 4] columnwise order
M = reshape(V, size(C)) % [1, 2; 3, 4]

This C-Mex is up to 5 times faster than CAT(C{:}), HORZCAT or CELL2MAT.

Pre-compiled Mex-files can be downloaded:
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.

Cite As

Jan (2021). Cell2Vec (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

Anton Semechko

Tanmay Rajpathak



@Misha, you have to compile the C-file as described in the section "COMPILATION" in the help text - see "help Cell2Vec".


Hi Jan,
Am I doing something wrong in trying to use this patch? I've dropped it in my main matlab folder. When I try to run:

a =

1 5 9
2 6 10
3 7 11
4 8 12

>> v = cell2vec(a)

i get an error:
Error using Cell2Vec (line 41)
Cannot find Mex file of Cell2Vec

Quant Guy

This is very useful tool and important submission. I was able trivially to reimplement the out of the box implementation of cell2mat which is very slow and got huge increases in overall speed!!

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!