Path: news.mathworks.com!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!news.in2p3.fr!in2p3.fr!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail
From: Lothar Schmidt <vapooroop@gmx.net>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Creating a new vector based on unique entries
Date: Thu, 14 May 2009 15:58:46 +0200
Organization: T-Online
Lines: 25
Message-ID: <guh86e$5iq$01$1@news.t-online.com>
References: <guh7ap$s7n$1@fred.mathworks.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.t-online.com 1242309646 01 n5722 +itQQQkl9yQQVBa 090514 14:00:46
X-Complaints-To: usenet-abuse@t-online.de
X-ID: EGDKDyZTYeBpedp+aA-yZQEf5ifvRIB61c+v0XTgR7CP7e0-8+Hp8v
User-Agent: Thunderbird 2.0.0.21 (Windows/20090302)
In-Reply-To: <guh7ap$s7n$1@fred.mathworks.com>
Xref: news.mathworks.com comp.soft-sys.matlab:539920


Anna Chen schrieb:
> Hello there,
> I have a question on something that I just can't seem to get to work correctly.  I have a dataset imported from excel that looks like this:
> 
> cat          2
> cat          3
> cat          0
> dog         4
> dog         5
> mouse     6
> 
> Where the first column is cell and the second is double.  How would I create a vector that has three elements, the first that averages all the "cats," the second that averages all the "dogs" and the third that averages all the "mice"?  I've been trying combinations of for and while loops, but the different data classes are messing me up!
> 
> Thanks!

like this?

k=0;
for tmp=unique(animal.type),
	k=k+1;
	list.name{k}=tmp;
	index=find(strcmp(tmp,animal.type));
	list.mean(k)=mean(animal.num(index));
end
list