Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
Ian
Posts:
14
Registered:
9/21/10
|
|
Re: Sorting Matrices
Posted:
Sep 29, 2010 4:33 PM
|
|
"Jos (10584) " <#10584@fileexchange.com> wrote in message <i805or$1sm$1@fred.mathworks.com>... > "Ian " <ikirby23@yahoo.com> wrote in message <i801eh$djr$1@fred.mathworks.com>... > > "Jos (10584) " <#10584@fileexchange.com> wrote in message <i7vo79$onh$1@fred.mathworks.com>... > > > "Ian " <ikirby23@yahoo.com> wrote in message > > > * snip * > > > > Thanks guys very helpfull so far, I can now find all the consectutive numbers from column 1, the problem I have now is it needs to be sorted providing what the max value is of colum 2, for example: > > > > > > > > A=[ 1030 2520 > > > > 1031 2375 > > > > 1315 3618 > > > > 1317 2694] > > > > > > > > So for 1030 and 1031 the max value for column 2 is 2520, and for 1315 and 1317 the max value is 3618. I would then want disregard rows 1031 and 1317 and keep 1030 and 1031. > > > > > > You have to be a little bit clearer on what you mean by "rows that are consecutive". In my opinion, 1315 and 1317 are NOT consecutive. And you cannot both keep and disregard 1031 (but I assume that is a spelling error ;-) ) > > > > > > Jos > > > > Hi Jos, > > > > Sorry I have made a couple of mistakes here, I will try to explain this again a bit clearer. In the matrix below, I want to find the maximum value of column 2 for every consecutive number of column 1. > > > > > > A=[ 1030 2520 > > 1031 2375 > > 1315 3618 > > 1316 2694 > > 1317 2798]; > > > > So in the matrix there are two sets of consectutive numbers in column 1, 1st set 1030 & 1031, 2nd set 1315, 1316 & 1317. What I want do is find the max value of column 2 for each set of consecutive numbers, so the maximum value for the first set would be 2520 and the maximum value for the second set would be 3618. I would then want to keep the entire row for the maximum values (1030 & 1315) and bin the rest (1031,1316 & 1317). > > > > I hope this is a little clearer of what I am trying to acheive, this example is only a little snipit of the data set I am workin with, I need something that will work on a data set which has 4000 rows and 2 columns. > > My code in an earlier post does exactly what you're after (i.e. the "keep" part, I am not sure what you mean by "bin the rest") !! > > M2 = sortrows(M,[1 -2]) ; % N-by-2 data set > TF = [true ; diff(M(:,1))>1] > M2keep = M2(TF,:) > M2bin = M2(~TF,:) > > hth > Jos
Your code does find the maximum two values for column 2 and gaves you 1315 and 1317, but what I want to do is just find the maximum for each set seperatley, so for rows 1030 & 1031, I want to find the maximum value of column 2, which would only be out of 2520 & 2375, as the maximum would be 2520, I would keep 1030. For the 2nd set 1315,1316 & 1317, I want to be able to find the maximum for these rows only and keep that one, which would be 361 8 (1315). I'm sorry if I'm not explanning this problem very well, but I do appreciate your help.
Thankyou
Ian
|
|
|
|