Daniel@0: % ASORT Daniel@0: % a pedestrian NUMERICAL SORTER of ALPHANUMERIC data Daniel@0: Daniel@0: % - create some data Daniel@0: d = { Daniel@0: % strings with one valid alphanumeric number Daniel@0: % sorted numerically Daniel@0: '-inf' Daniel@0: 'x-3.2e4y' Daniel@0: 'f-1.4' Daniel@0: '-.1' Daniel@0: '+ .1d-2' Daniel@0: '.1' Daniel@0: 'f.1' Daniel@0: 'f -+1.4' Daniel@0: 'f.2' Daniel@0: 'f.3' Daniel@0: 'f.10' Daniel@0: 'f.11' Daniel@0: '+inf' Daniel@0: ' -nan' Daniel@0: '+ nan' Daniel@0: 'nan' Daniel@0: % strings with many numbers or invalid/ambiguous numbers Daniel@0: % sorted in ascii dictionary order Daniel@0: ' nan nan' Daniel@0: '+ .1e-.2' Daniel@0: '-1 2' Daniel@0: 'Z12e12ez' Daniel@0: 'inf -inf' Daniel@0: 's.3TT.4' Daniel@0: 'z12e12ez' Daniel@0: % strings without numbers Daniel@0: % sorted in ascii dictionary order Daniel@0: ' . .. ' Daniel@0: '.' Daniel@0: '...' Daniel@0: '.b a.' Daniel@0: 'a string' Daniel@0: 'a. .b' Daniel@0: }; Daniel@0: % ... and scramble it... Daniel@0: rand('seed',10); Daniel@0: d=d(randperm(numel(d))); Daniel@0: Daniel@0: % - run ASORT with Daniel@0: % verbose output: <-v> Daniel@0: % keep additional results: <-d> Daniel@0: o=asort(d,'-v','-d'); Daniel@0: % - or Daniel@0: % p=asort(char(d),'-v','-d'); Daniel@0: Daniel@0: % - show results Daniel@0: o Daniel@0: o.anr Daniel@0: Daniel@0: % - run ASORT with no-space/template options Daniel@0: % NOTE the impact of -w/-t order! Daniel@0: s={'ff - 1','ff + 1','- 12'}; Daniel@0: % RAW Daniel@0: o=asort(s,'-v'); Daniel@0: % remove SPACEs Daniel@0: o=asort(s,'-v','-w'); Daniel@0: % remove TEMPLATE(s) Daniel@0: o=asort(s,'-v','-t',{'ff','1'}); Daniel@0: % remove TEMPLATE(s) than SPACEs Daniel@0: o=asort(s,'-v','-t','1','-w'); Daniel@0: % remove SPACEs than TEMPLATE(s) Daniel@0: o=asort(s,'-v','-w','-t','1'); Daniel@0: