Sort an Array with sortrows ( ) with two columns
38 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Patrick Benz
el 19 de Feb. de 2021
Hey guys,
I'm sorting an 82x4 arraywith sortrows. I want it to be sorted in a descending way. First the second column shall be significant and for tiebreakers the third column.
My code is:
Knotenpaare=sortrows(Auswertung,[2 3],'descend')
where Auswertung is the array. The first 40 rows of the array are sorted beautifully. But at the moment the values in the second column switch from positive to negative the sorting changes.
Why are the values in the third column now ascending?
Is there a better way to sort these kinds of arrays ?
7 comentarios
Patrick Benz
el 24 de Feb. de 2021
Editada: Patrick Benz
el 24 de Feb. de 2021
dpb
el 24 de Feb. de 2021
"Is there an option to cut the number after 5 digits off? and not only visual."
node_Num=sign(node_Num).*floor(abs(node_Num)*1E5)/1E5;
Respuesta aceptada
Stephen23
el 24 de Feb. de 2021
There are probably nicer ways to do this, as this unfortunately changes the data itself. If required, you could use the index output from sortrows to sort the original data matrix.
format long g
S = load('Auswertungsknoten.mat');
A = S.Auswertung
for k = 1:size(A,2)
[U,X,Y] = uniquetol(A(:,k),1e-3);
A(:,k) = U(Y);
end
A
B = sortrows(A,[-2,-3])
B(38:48,:)
Más respuestas (1)
the cyclist
el 19 de Feb. de 2021
See my answer (and other comments) to this very similar question. (As with the comments above, the premise is that the displayed value is not sufficient to see a tiny difference between the numbers.)
0 comentarios
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!