qsort

Sort data with user-supplied comparison function
5 download
Aggiornato 31 mar 2022

Visualizza la licenza

Some examples of usage:
% Sort numerical array in descending order
A=rand(1,100000); tic; [As,is]=qsort(A, @(x,y) y-x); toc
% Sort strings
s = string(randi(200,1,20))
ss = qsort(s, @(x,y) double(x)-double(y))
% Sort structures
s = struct('name',{'smith' 'jackson' 'anna'},'yearofbirth', {40 70 60});
ss = qsort(s, @(x,y) x.yearofbirth-y.yearofbirth);
{ss.name} % returns {'smith'} {'anna'} {'jackson'}
[ss.yearofbirth] % returns 40 60 70
% Sort cell array
c = num2cell(struct('name',{'smith' 'jackson' 'anna'},'yearofbirth', {40 70 60}));
cs = qsort(c, @(x,y) x{1}.yearofbirth-y{1}.yearofbirth);
cs{:}

Cita come

Bruno Luong (2024). qsort (https://www.mathworks.com/matlabcentral/fileexchange/109104-qsort), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2022a
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux
Tag Aggiungi tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Versione Pubblicato Note della release
1.0.0