What is the equation for sortrows
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I was wondering what the equivalent equation for (sortrows) in Matlab. Let's say:
B = sortrows(A,2)
If there is an idea, I really appreciate because I just want to understand the concept mathematically
2 commentaires
Rik
le 20 Août 2018
You mean what the specific algorithm is that Mathworks used to implement this? They will probably not tell you.
And there is a difference between algorithm and equation.
What sortrows is doing (or something equivalent) is this:
function B=equivalent_to_sortrows(A,col)
[~,sort_order]=sort(A(:,col));
B=A(sort_order,:);
end
So the meat of the algorithm is just a sort.
Rik
le 20 Août 2018
Please post your comment as a comment, and not in the answer field. Their order can change, which makes reading the thread very confusing later on.
As far as I know there is not an equation that describes a sort algorithm, other than the trivial solution:
B=f(A,c)
where f sorts A according to column c
which would be a valid mathematical description, but would tell you anything.
Réponses (1)
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!