GROUP2CELL - group values into cells
C = GROUP2CELL(V,G) returns a N-by-1 cell array in which the values V are grouped as row vectors into separate cells according to the values in G. Both G and V should have the same number of elements. N is the number of different values in G. Each cell in C is a row vector.
[C,GR] = GROUP2CELL(V,G) also returns the groups in GR, so that C{i} = V(G==GR(i)).
The grouping variable can be a cell array of strings.
Examples:
[C, GG] = group2cell([1 2 3 4 5 6],[1 6 2 1 6 1]) ;
% returns the cell array {[1 4 6] ; [3] ; [2 5]} in C and [1 2 6] in GG
years = [1956 1978 1982 1987 2001 2006] ;
temp = {'normal','cold','hot','normal','cold','hot'} ;
C = group2cell(years,temp)
See also MAT2CELL, CELLFUN, CAT
and NONES, COUNTMEMBER (on the Matlab File Exchange)
Cite As
Jos (10584) (2024). GROUP2CELL (https://www.mathworks.com/matlabcentral/fileexchange/11192-group2cell), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 | added functionality of grouping variable to be a cell array of strings |