annotate aim-mat/tools/sortstruct.m @ 0:74dedb26614d

Initial checkin of AIM-MAT version 1.5 (6.4.2011).
author tomwalters
date Fri, 20 May 2011 12:32:31 +0100
parents
children 20ada0af3d7d
rev   line source
tomwalters@0 1 % tool
tomwalters@0 2 %
tomwalters@0 3 % INPUT VALUES:
tomwalters@0 4 %
tomwalters@0 5 % RETURN VALUE:
tomwalters@0 6 %
tomwalters@0 7 %
tomwalters@0 8 % (c) 2003-2008, University of Cambridge, Medical Research Council
tomwalters@0 9 % Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
tomwalters@0 10 % http://www.pdn.cam.ac.uk/cnbh/aim2006
tomwalters@0 11 % $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
tomwalters@0 12 % $Revision: 585 $
tomwalters@0 13
tomwalters@0 14 function ret=sortstruct(str,topic,nr_second_dimension)
tomwalters@0 15 % sorts the structure str by the values in "topic"
tomwalters@0 16 % if topic is twodimensional, then "nr_second_dimension" gives the chosen
tomwalters@0 17 % number
tomwalters@0 18
tomwalters@0 19
tomwalters@0 20 if nargin < 3
tomwalters@0 21 nr=size(str,2);
tomwalters@0 22 for i=1:nr
tomwalters@0 23 sortcount(i)=eval(sprintf('str{%d}.%s',i,topic));
tomwalters@0 24 end
tomwalters@0 25 for i=1:nr
tomwalters@0 26 [ismax,womax]=max(sortcount);
tomwalters@0 27 ret{i}=str{womax};
tomwalters@0 28 sortcount(womax)=-inf; % den möchte ich nicht mehr sehen!
tomwalters@0 29 end
tomwalters@0 30 else
tomwalters@0 31 nr=size(str,2);
tomwalters@0 32 for i=1:nr
tomwalters@0 33 sortcount(i)=eval(sprintf('str(%d).%s(%d)',i,topic,nr_second_dimension));
tomwalters@0 34 end
tomwalters@0 35 for i=1:nr
tomwalters@0 36 [ismax,womax]=max(sortcount);
tomwalters@0 37 ret(i)=str(womax);
tomwalters@0 38 sortcount(womax)=-inf; % den möchte ich nicht mehr sehen!
tomwalters@0 39 end
tomwalters@0 40 end