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 18:42:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 69
Message-ID: <guholp$8h7$1@fred.mathworks.com>
References: <guh7ap$s7n$1@fred.mathworks.com> <guh86e$5iq$01$1@news.t-online.com> <guh9i2$r8f$1@fred.mathworks.com> <guhfp9$495$03$1@news.t-online.com>
Reply-To: "Anna Chen" <icedredtea@yahoo.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1242326521 8743 172.30.248.35 (14 May 2009 18:42:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 14 May 2009 18:42:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1455324
Xref: news.mathworks.com comp.soft-sys.matlab:540014


hi lothar,
i had to change to
for k = 1:1:3
for tmp=unique(animal.type),
	list.name{k}=tmp {k};
	index=find(strcmp(tmp{k},animal.type));
	list.mean(k)=mean(animal.num(index));
 end

or else the two things in the strcmp wouldn't match.  

thanks so much for your help and your explanations!  now i have a better grasp on this
 =)  also, before i never knew that creating list.x and llist.y would make a list with "x" and "y"!  
thanks again!


Lothar Schmidt <vapooroop@gmx.net> wrote in message <guhfp9$495$03$1@news.t-online.com>...
> Anna Chen schrieb:
> > 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
> 
> supposing that
> 
> animal.type{1}='cat'
> animal.type{2}='dog'
> ...
> animal.num(1)=4
> animal.num(2)=7
> ...
> 
> tmp will be a cell with one og the anymal types.
> 
> strcmp(tmp,animal.type)
> 
> will compare any animal type to the current tmp (type of animal) and 
> will give you 1 if type=tmp and 0 if type~=tmp
> find(this_logical) will give you the index of identical animaltypes
> 
> mean(animal.num(index)) gives the mean of the appropriate numbers
> 
> is this the answer to your question?