How to sort a two column vector

7 Ansichten (letzte 30 Tage)
Jórdan Venâncio Leite
Jórdan Venâncio Leite am 2 Jun. 2020
Kommentiert: Rena Berman am 12 Okt. 2020
I need to order this two column vector (attached) in such a way that the first column (x) is ordered ascending and the second column follows this order. In other words, it is very important to me that the values in the second column remain the same for each value of x.
Thanks in advance.
  4 Kommentare
Stephen23
Stephen23 am 11 Jun. 2020
Original question by Jórdan Venâncio Leite on 2nd June 2020 retrieved from Google Cache (uploaded data could not be retrieved):
"How to sort a two column vector"
I need to order this two column vector (attached) in such a way that the first column (x) is ordered ascending and the second column follows this order. In other words, it is very important to me that the values in the second column remain the same for each value of x.
Thanks in advance.
Rena Berman
Rena Berman am 12 Okt. 2020
(Answers Dev) Restored edit

Melden Sie sich an, um zu kommentieren.

Antworten (2)

dpb
dpb am 2 Jun. 2020
s=sortrows(x);

KSSV
KSSV am 2 Jun. 2020
Let A be your vector of two columns.
[val,idx] = sort(A(:,1)) ; % sort the first column
iwant = A(idx,:) % arrange A in ascending order of first column

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by