Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Creating a new vector based on unique entries
Date: Fri, 15 May 2009 11:21:02 +0000 (UTC)
Organization: Erasmus MC
Lines: 38
Message-ID: <gujj6u$ljp$1@fred.mathworks.com>
References: <guh7ap$s7n$1@fred.mathworks.com> <guh86u$qca$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1242386462 22137 172.30.248.38 (15 May 2009 11:21:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 15 May 2009 11:21:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870065
Xref: news.mathworks.com comp.soft-sys.matlab:540181


"Andrey Rubshtein" <katana55@gmail.com> wrote in message <guh86u$qca$1@fred.mathworks.com>...
> a very quick and dirty solution to give you an idea
> 
> x = {'cat','cat','cat','dog','dog','mouse'};
> y = [2,3,0,4,5,6];
> 
> cats = strmatch('cat',x);
> dogs = strmatch('dog',x);
> mice = strmatch('mouse',x);
> 
> catsAvg = mean(y(cats));
> dogsAvg = mean(y(dogs));
> miceAvg = mean(y(mice));
> 
> disp(catsAvg);
> disp(dogsAvg);
> disp(miceAvg);
> 
> 
> Now write a loop which recognizes which different animals there are in x, and do it in more generic way

You might be interested in my GROUP2CELL function:

animals = {'cat','cat','cat','dog','dog','mouse'};
val = [2,3,0,4,5,6];

%engine
[R,gri] = group2cell(val,animals)
avg = cellfun(@mean,R) ;

% display result
[animals(gri).' num2cell(avg)]

GROUP2CELL can be found here:
http://www.mathworks.com/matlabcentral/fileexchange/11192

hth
Jos