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

조회 수: 1 (최근 30일)
Ammy
Ammy 2021년 5월 23일
댓글: Ammy 2021년 5월 23일
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
Torsten
Torsten 2021년 5월 23일
Thanks, I copied my comment into an answer field.
Ammy
Ammy 2021년 5월 23일
Thank you.

댓글을 달려면 로그인하십시오.

채택된 답변

Torsten
Torsten 2021년 5월 23일
Something like
As = sortrows(A);
x = As(y(:)+1,1)
where y is the vector of y-coordinates ?

추가 답변 (1개)

Kartikay Sapra
Kartikay Sapra 2021년 5월 23일
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
Ammy
Ammy 2021년 5월 23일
@Kartikay SapraThank you very much for your valueable comment, but my problem is solved with @Torsten answer.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by