Cody: Problem 30 - function Sortrows
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Marco Castelli
le 27 Juil 2012
Réponse apportée : Fatih Atilla PINAR
le 9 Juin 2020
Hi,
i'm "solving" number 30 cody's problem.
I think to solve that whit sortrows function.
If I have a z vector:
j = sqrt(-1);
z = [-4 6 3+4*j 1+j 0];
my funtion is:
function z = complexSort(z)
z(2,:)=sqrt(real(z).^2+imag(z).^2);
z=sortrows(z',-2);
z=z(:,1);
end
End it return the result
z =
6.0000 6.0000
3.0000 - 4.0000i 5.0000
-4.0000 4.0000
1.0000 - 1.0000i 1.4142
0 0
The question is: why imagine part in input is positive e sortrows trasform it in negative?
best regards
Marco
0 commentaires
Réponse acceptée
Plus de réponses (1)
Fatih Atilla PINAR
le 9 Juin 2020
function zSorted = complexSort(z)
zSorted = sort(z,2,'descend');
end
0 commentaires
Voir également
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!