Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Matching data based on columns Date: Sun, 15 Mar 2009 02:55:02 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 29 Message-ID: <gphqm6$eh5$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-03-blr.mathworks.com Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1237085702 14885 172.30.248.38 (15 Mar 2009 02:55:02 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Sun, 15 Mar 2009 02:55:02 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1756295 Xref: news.mathworks.com comp.soft-sys.matlab:524936 Hi all, I apologize in advance if this is a novice and trivial question but I would appreciate all the help I can get! I must have spent at least three days on trying to solve this problem and poured many hours on googling this solution but still to no avail. I want to sort data in the following format: A = [1 1 3 4 98 97 96; ... 1 1 3 4 98 93 92; ... 1 1 3 4 92 94 90; ... 2 3 4 5 79 88 90; ... 2 4 5 7 89 78 99; ... 2 6 9 7 89 78 99]; I want to sort the data based on the conditions of the first four columns of the matrix A. Moreover, for the rows that match the criteria, is it possible to get an average? Perhaps it is easier to explain with an example. That is, the resulting matrix should look like the following: B = [1 1 3 4 96 94.7 92.7; ... 2 3 4 5 79 88 90; ... 2 4 5 7 89 78 99; ... 2 6 9 7 89 78 99]; where 96 = 1/3 * (98 + 98 + 92) 94.7 = 1/3 * (97 + 93 + 94) 92.7 = 1/3 * (96 + 92 + 90) and whether the values in the last three columns match or not is irrelevant (i.e. as illustrated by the last two rows of matrix A). Thank you so much! PS. In effect, this is sort of like Excel's vlookup function (not quite, since I want three elements to match whereas Excel only allows for one and also that I want a calculation based on the matches).