Path: news.mathworks.com!not-for-mail
From: "Anna Chen" <icedredtea@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Creating a new vector based on unique entries
Date: Thu, 14 May 2009 14:24:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 31
Message-ID: <guh9i2$r8f$1@fred.mathworks.com>
References: <guh7ap$s7n$1@fred.mathworks.com> <guh86e$5iq$01$1@news.t-online.com>
Reply-To: "Anna Chen" <icedredtea@yahoo.com>
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 1242311042 27919 172.30.248.37 (14 May 2009 14:24:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 14 May 2009 14:24:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1455324
Xref: news.mathworks.com comp.soft-sys.matlab:539927


Thanks for everyone's help!  I guess i was having trouble with the string matching thing.
Lothar, I have a question for you.  when you do find(strcmp(tmp, animal.type)), won't that not work because tmp will be a cell with 3 elements and animal.type has 5?
Just wanted to understand the logic and improve my skills!


Lothar Schmidt <vapooroop@gmx.net> wrote in message <guh86e$5iq$01$1@news.t-online.com>...
> 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