Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7927811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:30:28+00:00 2026-06-03T19:30:28+00:00

I have a vector of coordinates called x. I want to get the element(s)

  • 0

I have a vector of coordinates called x. I want to get the element(s) with the min y coordinate:

a = find(x(:,2)==min(x(:,2))); % Contains indices

This returns the indexes of the elements with the smallest y coordinates. I say element*s* because sometimes this would return more than 1 value (e.g. (10,2) and (24,2) both have 2 as y coordinate and if 2 is the min y coordinate…).

Anyway, my next step is to sort (ascending) the elements with the min y coordinates according to their x coordinates. First I do:

b = sort(x(a,1));

The above operation might rearrange the elements with min y coordinates so I want to apply this rearrangement to a as well. So I do:

[v i] = ismember(b, x(:, 1));

Unfortunately, if there are elements with the same x value but different y values and one of these elements turns out to be a member of a (i.e. b) then the above matrix chooses it. For example if (10,2) and (24,2) are the elements with smallest y coordinates and there is a 3rd element (24, 13) then it will mess up the above operation. Is there a better way? I wrote my script using loops and everything was fine but in line with Matlab’s methodology I rewrote it and I fear my unfamiliarity with matlab is causing this error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:30:34+00:00Added an answer on June 3, 2026 at 7:30 pm

    Sorry, I might have misunderstood your question but lemme rephrase what I think you want here:
    You have a set of 2D coordinates:

    x = [24,2; 10,2; 24,13];
    

    You want the pairs of coordinates to stay together (24,2) (10,2) and (24,13). And you want to find the pairs of coordinates that has the min y-coordinate and if there are multiples, then you want to sort them by x-coordinate. And you want the row indices of what those coordinate pairs were in the original matrix x. So in other words, you want a final answer of:

    v = [10,2; 24,2];
    i = [2,1];
    

    If I understood correctly, then this is how you can do it:

    (Note: I changed x to have one more pair (40,13) to illustrate the difference between idx(i) and i)

    >> x = [40,13; 24,2; 10,2; 24,13];
    >> idx = find(x(:,2)==min(x(:,2))) %Same as what you've done before.
    
    idx =
    
         2
         3
    
    >> [v,i] = sortrows(x(idx,:)) %Use sortrows to sort by x-coord while preserving pairings
    
    v =
    
        10     2
        24     2
    
    
    i = % The indices in x(idx,:)
    
         2
         1
    
    >> idx(i) %The row indices in the original matrix x
    
    ans =
    
         3
         2
    

    And finally, if this is not what you wanted, can you indicate what you think your answer [v,i] should be in the example you gave?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 2D vector which contains the coordinates which I want to represent
I have a vector that I want to insert into a set . This
I have a class called Coordinate, and am building a vector of these coordinate
I have a vector of pointers like so: vector<Item*> items; I want to clear
I have a vector-like class that contains an array of objects of type T
I have a vector of beans that holds information I want to display in
TLDR : I have an Openlayers map with a layer called 'track' I want
If I have two vector coordinates representing positions on the surface of the earth
Suppose I have a vector of points as polar coordinates. Suppose one of those
I have a euclidean vector a sitting at the coordinates (0, 1) . I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.