Code covered by the BSD License  

Highlights from
GROUP2CELL

4.5

4.5 | 2 ratings Rate this file 3 Downloads (last 30 days) File Size: 1.96 KB File ID: #11192

GROUP2CELL

by Jos (10584)

 

25 May 2006 (Updated 09 Aug 2006)

group values into cells

| Watch this File

File Information
Description

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)

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
26 May 2006 Duane Hanselman

Based on the example given in the description, I don't understand how "the values V are grouped as row vectors into separate cells according to the values in G"??? I don't see the correspondence at all. Can you provide a more illustrative example and explanation. Also, in what applications might this function be useful? As it stands, this function does not make any sense to me.

26 May 2006 Richard Johnson

There are 3 common ways to deal with data in a "ragged" array: pad with nan or 0, use a cell array, or use a grouping variable. This function provides a useful translation from grouping variable organization to cell organization.
It would be improved if the variable names in the help lines more closely matched those in the function line.
A useful but more complex generalization would be to allow a non-numeric grouping variable.

17 Mar 2011 Rossella  
Please login to add a comment or rating.
Updates
09 Aug 2006

added functionality of grouping variable to be a cell array of strings

Tag Activity for this File
Tag Applied By Date/Time
matrices Jos (10584) 22 Oct 2008 08:26:52
cell Cristina McIntire 23 Feb 2009 15:31:51
group Cristina McIntire 23 Feb 2009 15:31:51
count Cristina McIntire 23 Feb 2009 15:31:51
cellfun Cristina McIntire 23 Feb 2009 15:31:51
hist Cristina McIntire 23 Feb 2009 15:31:51
cellfun Weimin 11 Nov 2009 00:51:27

Contact us at files@mathworks.com