how to arrange x-coordinate w.r.t y-coordinates?

I have a pair of coordinates (x,y) , I arranged it in increasing order of y by using
sortrows(A,2) % A is matrix with first column as x-coordinate and 2nd column as y-coordinates.
I have
(4,0)
(10,1)
(7,2)
(6,3)
(9,4)
(1,5)
(1,6)
(9,7)
(6,8)
(7,9)
(10,10)
But now I want to arrange the x-coordinates if y-coordinate is given like I want to arrange x ,w.r.t y-coordinate [ 0 7 7 4 1 7 3 3 10 2] , In other words I want tp arrange it w.r.t to y-coordinate if y is given how to search for x ,I need the following
(4,0)
(9,7)
(9,7)
(9,7)
(10,4)
(9,7)
(6,3)
(6,3)
(10,10)
(7,2)

7 Kommentare

Torsten
Torsten am 23 Mai 2021
Bearbeitet: Torsten am 23 Mai 2021
The y-coordinate you prescribe in your vector always exists in the matrix ? And after sorting they come out to be 0,1,2,3,4,5,6,7,...,n ?
Ammy
Ammy am 23 Mai 2021
Yes, the y-coordinate always exists, but I want a secific x-coordinate corresponding to y-coordinate [ 0 7 7 4 1 7 3 3 10 2]
Ammy
Ammy am 23 Mai 2021
The y-coordinate you prescribe in your vector always exists in the matrix ? Yes
And after sorting they come out to be 0,1,2,3,4,5,6,7,...,n ? Yes, exactly
Torsten
Torsten am 23 Mai 2021
Bearbeitet: Torsten am 23 Mai 2021
Something like
As = sortrows(A,2);
x = As(y(:)+1,1)
where y is the vector of y-coordinates ?
Ammy
Ammy am 23 Mai 2021
@Torsten thank you very much. its working. How can I accept this answer?
Torsten
Torsten am 23 Mai 2021
Thanks, I copied my comment into an answer field.
Ammy
Ammy am 23 Mai 2021
Thank you.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Torsten
Torsten am 23 Mai 2021

0 Stimmen

Something like
As = sortrows(A);
x = As(y(:)+1,1)
where y is the vector of y-coordinates ?

Weitere Antworten (1)

Kartikay Sapra
Kartikay Sapra am 23 Mai 2021

0 Stimmen

A = [1 2; 3 4; 5 6]
map = containers.Map
[row col] = size(A)
for i = 1:row
A(i,1)
map(int2str(A(i,1))) = int2str(A(i,2))
end
y = input('Enter y coordinate')
str2num(map(int2str(y)))
You can try using a map object, here, you can place y co-ordinates as keys and x co-ordinates as value. Whenever we want the corresponding x value, search value of y

1 Kommentar

Ammy
Ammy am 23 Mai 2021
@Kartikay SapraThank you very much for your valueable comment, but my problem is solved with @Torsten answer.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Mathematics finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 23 Mai 2021

Kommentiert:

am 23 Mai 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by