Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Combining elements in rows into single numbers and finding corresponding elements
Date: Tue, 17 May 2011 01:02:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 38
Message-ID: <iqsheb$mdq$1@newscl01ah.mathworks.com>
References: <iqsdcv$b41$1@newscl01ah.mathworks.com> <iqsgan$j9u$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1305594123 22970 172.30.248.37 (17 May 2011 01:02:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 17 May 2011 01:02:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2876404
Xref: news.mathworks.com comp.soft-sys.matlab:727140

"Roger Stafford" wrote in message <iqsgan$j9u$1@newscl01ah.mathworks.com>...
> "jrockv6e" wrote in message <iqsdcv$b41$1@newscl01ah.mathworks.com>...
> > This is a picture of a simple example of what I want to do.
> > 
> > http://i.imgur.com/eZlED.png
> > 
> > Where Y, F, and W are matrices. 
> > 
> > My initial idea is to combine all the elements in each row of F into a single number. I have looked at concatenating but it doesn't seem to do what I want.
> > 
> > So that would give me, 
> > e = [111; 111; 222; 222] 
> > 
> > and then I need to find the corresponding values of Y and W that fall within the group 111 to do the operation. 
> > 
> > I'm heading in the right direction?  any hints would be greatly appreciated. Thanks for looking!
> - - - - - - - - - -
>   I have trouble understanding exactly what you want.  The following seems the most likely solution, but if that is not correct, you need to expand considerably upon what you wrote.  In particular your array 'e' does not seem compatible with the referenced file, "eZlED.png".
> 
>  [u,~,n] = unique(F,'rows');
>  C = accumarray(n,Y,[length(u),1]) ./ accumarray(n,W,[length(u),1]);
> 
> Roger Stafford

Thanks Roger that does the job. I guess there was no need for 'e'.

Is there a reason why the output has a 'NaN' ? This is what I have.

Y=[1; 2; 3; 4; 5];
F = [1 1 1; 1 1 1; 1 1 1; 2 2 2; 2 2 2];
W= [9; 8; 7; 6; 5];
[u,z,n] = unique(F,'rows');
C = accumarray(n,Y,[length(u),1]) ./ accumarray(n,W,[length(u),1])

C =
    0.2500
    0.8182
       NaN