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: Thu, 14 May 2009 14:01:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 19
Message-ID: <guh86u$qca$1@fred.mathworks.com>
References: <guh7ap$s7n$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1242309662 27018 172.30.248.37 (14 May 2009 14:01:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 14 May 2009 14:01:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1839335
Xref: news.mathworks.com comp.soft-sys.matlab:539919


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