Sorting the vector y wrt the vector x?
20 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MEET SHAH
am 16 Apr. 2022
Beantwortet: Image Analyst
am 17 Apr. 2022
I have two vectors x and y
x = 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.66
y = 0.051998 0.084698 0.117398 0.150098 0.182798 0.215498 0.248198 0.19 0.09 0.235118
I want to make the matrix [x,y] in such a way that x is in ascending, i.e., results should be
x = 0.1 0.2 0.3 0.4 0.5 0.6 0.66 0.7 0.8 0.9
y = 0.051998 0.084698 0.117398 0.150098 0.182798 0.215498 0.235118 0.248198 0.19 0.09
Any suggestions are apreciated and thankyou in advance for your help !!
0 Kommentare
Akzeptierte Antwort
Voss
am 16 Apr. 2022
x = [ 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.66 ];
y = [ 0.051998 0.084698 0.117398 0.150098 0.182798 0.215498 0.248198 0.19 0.09 0.235118 ];
[~,idx] = sort(x);
M = [x(idx); y(idx)]
0 Kommentare
Weitere Antworten (1)
Image Analyst
am 17 Apr. 2022
Slightly different but essentially the same
x = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.66];
y = [0.051998, 0.084698, 0.117398, 0.150098, 0.182798, 0.2154908, 0.248198, 0.19, 0.09, 0.235118];
% Sort (and replace) x and get the order in which it was sorted.
[x, sortOrder] = sort(x, 'ascend')
% Sort y using the same order as x used, replacing original y with new, sorted y.
y = y(sortOrder)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!