Data Sorting
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I am trying to sort some data which looks likes this:
0.750000 1.850000 0.665590 0.008090 0.001350 70.507415 0.477660
0.740000 1.850000 0.636280 0.007960 0.000820 72.469248 0.496540
0.730000 1.850000 0.616250 0.007850 0.000400 74.696970 0.458810
0.720000 1.850000 0.599960 0.007740 0.000100 76.525510 0.164770
0.710000 1.70000 0.585730 0.007660 0.000000 76.466057 0.150690
0.700000 1.850000 0.573140 0.007590 0.000000 75.512516 0.111650
0.690000 1.850000 0.561880 0.007530 0.000000 74.618858 0.124110
0.680000 1.850000 0.551720 0.007470 0.000030 73.562667 0.058280
0.760000 1.850000 0.695240 0.008480 0.004090 55.309467 0.571900
0.770000 1.850000 0.708020 0.009050 0.006680 45.010807 0.627590
0.775000 1.90000 0.706110 0.009370 0.007870 40.957657 0.645790
I have read the data in and I am trying to sort it. I switched the place of the first two columns as I wanted to look at the data that way. I want the data sorted in ascending order of the second column shown(which was switched to the first column), but I also want the corresponding row kept. The problem I am having is that as there are lots of '1.850000' figures, it sorts the data but then only associates the other columns with that of the first 1.85 figure, meaning that - that row is repeated. My code looks like:
data_Alpha_sort = sort(data_5230,1,'ascend');
for i = 1:(length(data_Alpha_sort)-1) ind = find(data_Alpha_sort(i,1) == data_5230(:,1)); Alpha_sa(i,1) = data_5230(ind(1),1); ...etc... end
Does anyone have any suggestions about how I can sort this out?
Many Thanks
0 Kommentare
Akzeptierte Antwort
Oleg Komarov
am 24 Feb. 2012
I don't understand completely what you're trying to achieve, but to sort a matrix according to a certain column use sortrows:
sortrows(data_5230,1)
You can sort according several columns, for example to sort by the 1st column and then by the 2nd:
sortrows(data_5230,1:2)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!