Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Matching rows in one matrix to elements of another matrix Date: Tue, 17 May 2011 20:14:04 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 26 Message-ID: <iqukuc$q9n$1@newscl01ah.mathworks.com> References: <iqtvln$9mp$1@newscl01ah.mathworks.com> <iqu0r6$ds9$1@newscl01ah.mathworks.com> <iqu3uj$ort$1@newscl01ah.mathworks.com> <iqu7ir$8a7$1@newscl01ah.mathworks.com> <iqugfq$amg$1@newscl01ah.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-03-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1305663244 26935 172.30.248.48 (17 May 2011 20:14:04 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Tue, 17 May 2011 20:14:04 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:727339 "jrockv6e" wrote in message <iqugfq$amg$1@newscl01ah.mathworks.com>... > Sorry to bring this topic back, but it seems that I’m still having problems, in part due to my explanation and trying to simplify the problem. I will try to explain in much clearer way. I have the following: > > - matrix b with a set number of values (5 in this case) > b = [0.0276; 0.0129; 0.4283; 0.4621; 0.9996]; > > - matrix f has a corresponding row for each value of b > f = [1 1 1; 1 1 2; 1 2 1; 2 1 1; 2 2 1]; > > as shown in this image: http://i.imgur.com/U5AcB.png > > So my code generates matrix j which can have infinite amount of rows in the same format as in matrix f. I want to assign each row in 'j' a corresponding b value. > > as shown in this image: http://i.imgur.com/2fyN0.png > > so for this example if my is: j = [ 1 1 1; 1 1 1; 1 2 1; 1 2 1; 2 2 2]; > > my output would be: x=[0.0276; 0.0276; 0.4283; 0.4283; 0.996]; > > I hope I was clear. Thanks. - - - - - - - - - - What you have just described is very different from the two-array problem previously presented. For this problem you need the 'ismember' function using the 'rows' option. I challenge you to figure out how to use the 'loc' (the second) output of 'ismember' to accomplish the task you are asking about. You can do it in just two easy lines. Roger Stafford