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