<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251363</link>
    <title>MATLAB Central Newsreader - Creating a new vector based on unique entries</title>
    <description>Feed for thread: Creating a new vector based on unique entries</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 14 May 2009 13:46:02 -0400</pubDate>
      <title>Creating a new vector based on unique entries</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251363#649843</link>
      <author>Anna Chen</author>
      <description>Hello there,&lt;br&gt;
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:&lt;br&gt;
&lt;br&gt;
cat          2&lt;br&gt;
cat          3&lt;br&gt;
cat          0&lt;br&gt;
dog         4&lt;br&gt;
dog         5&lt;br&gt;
mouse     6&lt;br&gt;
&lt;br&gt;
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 &quot;cats,&quot; the second that averages all the &quot;dogs&quot; and the third that averages all the &quot;mice&quot;?  I've been trying combinations of for and while loops, but the different data classes are messing me up!&lt;br&gt;
&lt;br&gt;
Thanks!</description>
    </item>
    <item>
      <pubDate>Thu, 14 May 2009 14:01:02 -0400</pubDate>
      <title>Re: Creating a new vector based on unique entries</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251363#649850</link>
      <author>Andrey Rubshtein</author>
      <description>a very quick and dirty solution to give you an idea&lt;br&gt;
&lt;br&gt;
x = {'cat','cat','cat','dog','dog','mouse'};&lt;br&gt;
y = [2,3,0,4,5,6];&lt;br&gt;
&lt;br&gt;
cats = strmatch('cat',x);&lt;br&gt;
dogs = strmatch('dog',x);&lt;br&gt;
mice = strmatch('mouse',x);&lt;br&gt;
&lt;br&gt;
catsAvg = mean(y(cats));&lt;br&gt;
dogsAvg = mean(y(dogs));&lt;br&gt;
miceAvg = mean(y(mice));&lt;br&gt;
&lt;br&gt;
disp(catsAvg);&lt;br&gt;
disp(dogsAvg);&lt;br&gt;
disp(miceAvg);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Now write a loop which recognizes which different animals there are in x, and do it in more generic way</description>
    </item>
    <item>
      <pubDate>Thu, 14 May 2009 13:58:46 -0400</pubDate>
      <title>Re: Creating a new vector based on unique entries</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251363#649851</link>
      <author>Lothar Schmidt</author>
      <description>Anna Chen schrieb:&lt;br&gt;
&amp;gt; Hello there,&lt;br&gt;
&amp;gt; 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:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; cat          2&lt;br&gt;
&amp;gt; cat          3&lt;br&gt;
&amp;gt; cat          0&lt;br&gt;
&amp;gt; dog         4&lt;br&gt;
&amp;gt; dog         5&lt;br&gt;
&amp;gt; mouse     6&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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 &quot;cats,&quot; the second that averages all the &quot;dogs&quot; and the third that averages all the &quot;mice&quot;?  I've been trying combinations of for and while loops, but the different data classes are messing me up!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks!&lt;br&gt;
&lt;br&gt;
like this?&lt;br&gt;
&lt;br&gt;
k=0;&lt;br&gt;
for tmp=unique(animal.type),&lt;br&gt;
	k=k+1;&lt;br&gt;
	list.name{k}=tmp;&lt;br&gt;
	index=find(strcmp(tmp,animal.type));&lt;br&gt;
	list.mean(k)=mean(animal.num(index));&lt;br&gt;
end&lt;br&gt;
list</description>
    </item>
    <item>
      <pubDate>Thu, 14 May 2009 14:24:02 -0400</pubDate>
      <title>Re: Creating a new vector based on unique entries</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251363#649858</link>
      <author>Anna Chen</author>
      <description>Thanks for everyone's help!  I guess i was having trouble with the string matching thing.&lt;br&gt;
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?&lt;br&gt;
Just wanted to understand the logic and improve my skills!&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Lothar Schmidt &amp;lt;vapooroop@gmx.net&amp;gt; wrote in message &amp;lt;guh86e$5iq$01$1@news.t-online.com&amp;gt;...&lt;br&gt;
&amp;gt; Anna Chen schrieb:&lt;br&gt;
&amp;gt; &amp;gt; Hello there,&lt;br&gt;
&amp;gt; &amp;gt; 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:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; cat          2&lt;br&gt;
&amp;gt; &amp;gt; cat          3&lt;br&gt;
&amp;gt; &amp;gt; cat          0&lt;br&gt;
&amp;gt; &amp;gt; dog         4&lt;br&gt;
&amp;gt; &amp;gt; dog         5&lt;br&gt;
&amp;gt; &amp;gt; mouse     6&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 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 &quot;cats,&quot; the second that averages all the &quot;dogs&quot; and the third that averages all the &quot;mice&quot;?  I've been trying combinations of for and while loops, but the different data classes are messing me up!&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thanks!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; like this?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; k=0;&lt;br&gt;
&amp;gt; for tmp=unique(animal.type),&lt;br&gt;
&amp;gt; 	k=k+1;&lt;br&gt;
&amp;gt; 	list.name{k}=tmp;&lt;br&gt;
&amp;gt; 	index=find(strcmp(tmp,animal.type));&lt;br&gt;
&amp;gt; 	list.mean(k)=mean(animal.num(index));&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; list</description>
    </item>
    <item>
      <pubDate>Thu, 14 May 2009 16:08:18 -0400</pubDate>
      <title>Re: Creating a new vector based on unique entries</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251363#649907</link>
      <author>Lothar Schmidt</author>
      <description>Anna Chen schrieb:&lt;br&gt;
&amp;gt; Thanks for everyone's help!  I guess i was having trouble with the string matching thing.&lt;br&gt;
&amp;gt; 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?&lt;br&gt;
&amp;gt; Just wanted to understand the logic and improve my skills!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Lothar Schmidt &amp;lt;vapooroop@gmx.net&amp;gt; wrote in message &amp;lt;guh86e$5iq$01$1@news.t-online.com&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; Anna Chen schrieb:&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; Hello there,&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; 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:&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; cat          2&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; cat          3&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; cat          0&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; dog         4&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; dog         5&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; mouse     6&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; 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 &quot;cats,&quot; the second that averages all the &quot;dogs&quot; and the third that averages all the &quot;mice&quot;?  I've been trying combinations of for and while loops, but the different data classes are messing me up!&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; Thanks!&lt;br&gt;
&amp;gt;&amp;gt; like this?&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; k=0;&lt;br&gt;
&amp;gt;&amp;gt; for tmp=unique(animal.type),&lt;br&gt;
&amp;gt;&amp;gt; 	k=k+1;&lt;br&gt;
&amp;gt;&amp;gt; 	list.name{k}=tmp;&lt;br&gt;
&amp;gt;&amp;gt; 	index=find(strcmp(tmp,animal.type));&lt;br&gt;
&amp;gt;&amp;gt; 	list.mean(k)=mean(animal.num(index));&lt;br&gt;
&amp;gt;&amp;gt; end&lt;br&gt;
&amp;gt;&amp;gt; list&lt;br&gt;
&lt;br&gt;
supposing that&lt;br&gt;
&lt;br&gt;
animal.type{1}='cat'&lt;br&gt;
animal.type{2}='dog'&lt;br&gt;
...&lt;br&gt;
animal.num(1)=4&lt;br&gt;
animal.num(2)=7&lt;br&gt;
...&lt;br&gt;
&lt;br&gt;
tmp will be a cell with one og the anymal types.&lt;br&gt;
&lt;br&gt;
strcmp(tmp,animal.type)&lt;br&gt;
&lt;br&gt;
will compare any animal type to the current tmp (type of animal) and &lt;br&gt;
will give you 1 if type=tmp and 0 if type~=tmp&lt;br&gt;
find(this_logical) will give you the index of identical animaltypes&lt;br&gt;
&lt;br&gt;
mean(animal.num(index)) gives the mean of the appropriate numbers&lt;br&gt;
&lt;br&gt;
is this the answer to your question?</description>
    </item>
    <item>
      <pubDate>Thu, 14 May 2009 18:42:01 -0400</pubDate>
      <title>Re: Creating a new vector based on unique entries</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251363#649944</link>
      <author>Anna Chen</author>
      <description>hi lothar,&lt;br&gt;
i had to change to&lt;br&gt;
for k = 1:1:3&lt;br&gt;
for tmp=unique(animal.type),&lt;br&gt;
	list.name{k}=tmp {k};&lt;br&gt;
	index=find(strcmp(tmp{k},animal.type));&lt;br&gt;
	list.mean(k)=mean(animal.num(index));&lt;br&gt;
&amp;nbsp;end&lt;br&gt;
&lt;br&gt;
or else the two things in the strcmp wouldn't match.  &lt;br&gt;
&lt;br&gt;
thanks so much for your help and your explanations!  now i have a better grasp on this&lt;br&gt;
&amp;nbsp;=)  also, before i never knew that creating list.x and llist.y would make a list with &quot;x&quot; and &quot;y&quot;!  &lt;br&gt;
thanks again!&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Lothar Schmidt &amp;lt;vapooroop@gmx.net&amp;gt; wrote in message &amp;lt;guhfp9$495$03$1@news.t-online.com&amp;gt;...&lt;br&gt;
&amp;gt; Anna Chen schrieb:&lt;br&gt;
&amp;gt; &amp;gt; Thanks for everyone's help!  I guess i was having trouble with the string matching thing.&lt;br&gt;
&amp;gt; &amp;gt; 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?&lt;br&gt;
&amp;gt; &amp;gt; Just wanted to understand the logic and improve my skills!&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Lothar Schmidt &amp;lt;vapooroop@gmx.net&amp;gt; wrote in message &amp;lt;guh86e$5iq$01$1@news.t-online.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; Anna Chen schrieb:&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&amp;gt; Hello there,&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&amp;gt; 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:&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&amp;gt; cat          2&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&amp;gt; cat          3&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&amp;gt; cat          0&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&amp;gt; dog         4&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&amp;gt; dog         5&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&amp;gt; mouse     6&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&amp;gt; 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 &quot;cats,&quot; the second that averages all the &quot;dogs&quot; and the third that averages all the &quot;mice&quot;?  I've been trying combinations of for and while loops, but the different data classes are messing me up!&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&amp;gt; Thanks!&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; like this?&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; k=0;&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; for tmp=unique(animal.type),&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; 	k=k+1;&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; 	list.name{k}=tmp;&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; 	index=find(strcmp(tmp,animal.type));&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; 	list.mean(k)=mean(animal.num(index));&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; end&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; list&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; supposing that&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; animal.type{1}='cat'&lt;br&gt;
&amp;gt; animal.type{2}='dog'&lt;br&gt;
&amp;gt; ...&lt;br&gt;
&amp;gt; animal.num(1)=4&lt;br&gt;
&amp;gt; animal.num(2)=7&lt;br&gt;
&amp;gt; ...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; tmp will be a cell with one og the anymal types.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; strcmp(tmp,animal.type)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; will compare any animal type to the current tmp (type of animal) and &lt;br&gt;
&amp;gt; will give you 1 if type=tmp and 0 if type~=tmp&lt;br&gt;
&amp;gt; find(this_logical) will give you the index of identical animaltypes&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; mean(animal.num(index)) gives the mean of the appropriate numbers&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; is this the answer to your question?</description>
    </item>
    <item>
      <pubDate>Thu, 14 May 2009 19:33:01 -0400</pubDate>
      <title>Re: Creating a new vector based on unique entries</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251363#649952</link>
      <author>us</author>
      <description>&quot;Anna Chen&quot; &amp;lt;icedredtea@yahoo.com&amp;gt; wrote in message &amp;lt;guh7ap$s7n$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello there,&lt;br&gt;
&amp;gt; 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:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; cat          2&lt;br&gt;
&amp;gt; cat          3&lt;br&gt;
&amp;gt; cat          0&lt;br&gt;
&amp;gt; dog         4&lt;br&gt;
&amp;gt; dog         5&lt;br&gt;
&amp;gt; mouse     6&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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 &quot;cats,&quot; the second that averages all the &quot;dogs&quot; and the third that averages all the &quot;mice&quot;?  I've been trying combinations of for and while loops, but the different data classes are messing me up!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks!&lt;br&gt;
&lt;br&gt;
one of the many solutions&lt;br&gt;
&lt;br&gt;
% the data&lt;br&gt;
% - note: your data combined in one cell for sake of brevity...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;d={&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'cat'          1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'cat'          2&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'dog'          4&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'cat'          3&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'dog'          8&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'mouse'          -10&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;};&lt;br&gt;
% the engine&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;n&#202;t(1,d{:,2});     % &amp;lt;- your 2nd data set...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[du,ix,ix]=unique(d(:,1));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r&#172;cumarray(ix,n,[],@mean);&lt;br&gt;
% the result&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disp([du,num2cell(r)]);&lt;br&gt;
%{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'cat'      [  2]&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'dog'      [  6]&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'mouse'    [-10]&lt;br&gt;
%}&lt;br&gt;
&lt;br&gt;
us</description>
    </item>
    <item>
      <pubDate>Thu, 14 May 2009 19:58:01 -0400</pubDate>
      <title>Re: Creating a new vector based on unique entries</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251363#649958</link>
      <author>us</author>
      <description>&quot;us&quot;&lt;br&gt;
the broken TMW newsreader starts to get on my nerves...&lt;br&gt;
&lt;br&gt;
one of the many solutions (hope it works this time...)&lt;br&gt;
- copy/paste&lt;br&gt;
&lt;br&gt;
% the data &lt;br&gt;
% - note: your data combined in one cell for sake of brevity... &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;d={ &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'cat'          1 &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'cat'          2 &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'dog'          4 &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'cat'          3 &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'dog'          8 &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'mouse'      -10 &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}; &lt;br&gt;
% the engine &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;n = cat(1,d{:,2});     % &amp;lt;- your 2nd data set... &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[du,ix,ix] = unique(d(:,1)); &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;r = accumarray(ix,n,[],@mean); &lt;br&gt;
% the result &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disp([du,num2cell(r)]); &lt;br&gt;
%{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'cat'      [  2]&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'dog'      [  6]&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'mouse'    [-10]&lt;br&gt;
%}&lt;br&gt;
&lt;br&gt;
us</description>
    </item>
    <item>
      <pubDate>Thu, 14 May 2009 20:10:16 -0400</pubDate>
      <title>Re: Creating a new vector based on unique entries</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251363#649964</link>
      <author>Siyi</author>
      <description>On May 14, 12:58&#160;pm, &quot;us &quot; &amp;lt;u...@neurol.unizh.ch&amp;gt; wrote:&lt;br&gt;
&amp;gt; &quot;us&quot;&lt;br&gt;
&amp;gt; the broken TMW newsreader starts to get on my nerves...&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; one of the many solutions (hope it works this time...)&lt;br&gt;
&amp;gt; - copy/paste&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; % the data&lt;br&gt;
&amp;gt; % - note: your data combined in one cell for sake of brevity...&lt;br&gt;
&amp;gt; &#160; &#160; &#160;d={&lt;br&gt;
&amp;gt; &#160; &#160; &#160; &#160; &#160; 'cat' &#160; &#160; &#160; &#160; &#160;1&lt;br&gt;
&amp;gt; &#160; &#160; &#160; &#160; &#160; 'cat' &#160; &#160; &#160; &#160; &#160;2&lt;br&gt;
&amp;gt; &#160; &#160; &#160; &#160; &#160; 'dog' &#160; &#160; &#160; &#160; &#160;4&lt;br&gt;
&amp;gt; &#160; &#160; &#160; &#160; &#160; 'cat' &#160; &#160; &#160; &#160; &#160;3&lt;br&gt;
&amp;gt; &#160; &#160; &#160; &#160; &#160; 'dog' &#160; &#160; &#160; &#160; &#160;8&lt;br&gt;
&amp;gt; &#160; &#160; &#160; &#160; &#160; 'mouse' &#160; &#160; &#160;-10&lt;br&gt;
&amp;gt; &#160; &#160; &#160;};&lt;br&gt;
&amp;gt; % the engine&lt;br&gt;
&amp;gt; &#160; &#160; &#160;n = cat(1,d{:,2}); &#160; &#160; % &amp;lt;- your 2nd data set...&lt;br&gt;
&amp;gt; &#160; &#160; &#160;[du,ix,ix] = unique(d(:,1));&lt;br&gt;
&amp;gt; &#160; &#160; &#160;r = accumarray(ix,n,[],@mean);&lt;br&gt;
&amp;gt; % the result&lt;br&gt;
&amp;gt; &#160; &#160; &#160;disp([du,num2cell(r)]);&lt;br&gt;
&amp;gt; %{&lt;br&gt;
&amp;gt; &#160; &#160; 'cat' &#160; &#160; &#160;[ &#160;2]&lt;br&gt;
&amp;gt; &#160; &#160; 'dog' &#160; &#160; &#160;[ &#160;6]&lt;br&gt;
&amp;gt; &#160; &#160; 'mouse' &#160; &#160;[-10]&lt;br&gt;
&amp;gt; %}&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; us&lt;br&gt;
&lt;br&gt;
us, I realized that accumarray(...,@mean) can be slower than using&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
r = accumarray(ix,n)./accumarray(ix,1);</description>
    </item>
    <item>
      <pubDate>Thu, 14 May 2009 20:32:02 -0400</pubDate>
      <title>Re: Creating a new vector based on unique entries</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251363#649970</link>
      <author>us</author>
      <description>Siyi &lt;br&gt;
&amp;gt; us, I realized that accumarray(...,@mean) can be slower than using&lt;br&gt;
&amp;gt; r = accumarray(ix,n)./accumarray(ix,1);&lt;br&gt;
&lt;br&gt;
that certainly is/may be correct in this particular case...&lt;br&gt;
however, i used the (more) generic syntax for educational purposes - eg, what if the OP needs the @sum or something else being applied to the clusters...&lt;br&gt;
&lt;br&gt;
just a thought&lt;br&gt;
us</description>
    </item>
    <item>
      <pubDate>Fri, 15 May 2009 11:21:02 -0400</pubDate>
      <title>Re: Creating a new vector based on unique entries</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/251363#650109</link>
      <author>Jos </author>
      <description>&quot;Andrey Rubshtein&quot; &amp;lt;katana55@gmail.com&amp;gt; wrote in message &amp;lt;guh86u$qca$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; a very quick and dirty solution to give you an idea&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; x = {'cat','cat','cat','dog','dog','mouse'};&lt;br&gt;
&amp;gt; y = [2,3,0,4,5,6];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; cats = strmatch('cat',x);&lt;br&gt;
&amp;gt; dogs = strmatch('dog',x);&lt;br&gt;
&amp;gt; mice = strmatch('mouse',x);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; catsAvg = mean(y(cats));&lt;br&gt;
&amp;gt; dogsAvg = mean(y(dogs));&lt;br&gt;
&amp;gt; miceAvg = mean(y(mice));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; disp(catsAvg);&lt;br&gt;
&amp;gt; disp(dogsAvg);&lt;br&gt;
&amp;gt; disp(miceAvg);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Now write a loop which recognizes which different animals there are in x, and do it in more generic way&lt;br&gt;
&lt;br&gt;
You might be interested in my GROUP2CELL function:&lt;br&gt;
&lt;br&gt;
animals = {'cat','cat','cat','dog','dog','mouse'};&lt;br&gt;
val = [2,3,0,4,5,6];&lt;br&gt;
&lt;br&gt;
%engine&lt;br&gt;
[R,gri] = group2cell(val,animals)&lt;br&gt;
avg = cellfun(@mean,R) ;&lt;br&gt;
&lt;br&gt;
% display result&lt;br&gt;
[animals(gri).' num2cell(avg)]&lt;br&gt;
&lt;br&gt;
GROUP2CELL can be found here:&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/11192&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/11192&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
hth&lt;br&gt;
Jos</description>
    </item>
  </channel>
</rss>

