Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Sorting ordered pairs

Subject: Sorting ordered pairs

From: Katie

Date: 27 Nov, 2012 05:44:29

Message: 1 of 3

I am trying to sort ordered pairs of a very large data set based on the criteria that
y(i) >= 17000 + 2*x(i).
I want to keep the ordered pairs that meet the criteria and get rid of the ones that don't. I was thinking about a for loop along the lines:

for i=1:length(x)
 if y(i)>= 17000+2.*x(i)
    y=y(i);
    x=x(i);

but then I didn't know where to go from there.
Any help would be appreciated.

Subject: Sorting ordered pairs

From: Roger Stafford

Date: 27 Nov, 2012 06:20:24

Message: 2 of 3

"Katie " <kaddipack@gmail.com> wrote in message <k91jvt$ptd$1@newscl01ah.mathworks.com>...
> I am trying to sort ordered pairs of a very large data set based on the criteria that
> y(i) >= 17000 + 2*x(i).
- - - - - - - - - -
  It's easy to eliminate the pairs that don't satisfy that criterion:

 b = (y>=17000+2*x);
 x1 = x(b); y1 = y(b);

  However you will have to decide in what way the resulting x1,y1 pairs are to be sorted. You haven't made that clear. Look at the documentation for the 'sort' and/or 'sortrows' functions to see how you might use them for your purpose.

  Or perhaps this elimination process itself was what you meant by the word 'sort'. If so, you shouldn't use that term. 'Sorting' has a specific meaning in computer science and in mathematics.

Roger Stafford

Subject: Sorting ordered pairs

From: Katie

Date: 27 Nov, 2012 12:39:09

Message: 3 of 3

"Roger Stafford" wrote in message <k91m38$2cq$1@newscl01ah.mathworks.com>...
> "Katie " <kaddipack@gmail.com> wrote in message <k91jvt$ptd$1@newscl01ah.mathworks.com>...
> > I am trying to sort ordered pairs of a very large data set based on the criteria that
> > y(i) >= 17000 + 2*x(i).
> - - - - - - - - - -
> It's easy to eliminate the pairs that don't satisfy that criterion:
>
> b = (y>=17000+2*x);
> x1 = x(b); y1 = y(b);
>
> However you will have to decide in what way the resulting x1,y1 pairs are to be sorted. You haven't made that clear. Look at the documentation for the 'sort' and/or 'sortrows' functions to see how you might use them for your purpose.
>
> Or perhaps this elimination process itself was what you meant by the word 'sort'. If so, you shouldn't use that term. 'Sorting' has a specific meaning in computer science and in mathematics.
>
> Roger Stafford

Yes, I shouldn't have used sort. Thank you so much!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us