Home > marsbar > @mardo > private > pr_sort_evs.m

pr_sort_evs

PURPOSE ^

function to sort event according to sort type

SYNOPSIS ^

function evs = pr_sort_evs(evs, sort_type, downf)

DESCRIPTION ^

 function to sort event according to sort type
 FORMAT evs = pr_sort_evs(evs, sort_type, downf)

 evs        - structure containing fields
              'names': names of events
              'e_spec': row1 = session row2 = event number
 sort_type  - one of 'session' 'event' 'name'
 downf      - 1 if descending sort, 0 otherwise (0 default)
 
 Returns
 evs        - sorted event structure
 
 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function evs = pr_sort_evs(evs, sort_type, downf)
0002 % function to sort event according to sort type
0003 % FORMAT evs = pr_sort_evs(evs, sort_type, downf)
0004 %
0005 % evs        - structure containing fields
0006 %              'names': names of events
0007 %              'e_spec': row1 = session row2 = event number
0008 % sort_type  - one of 'session' 'event' 'name'
0009 % downf      - 1 if descending sort, 0 otherwise (0 default)
0010 %
0011 % Returns
0012 % evs        - sorted event structure
0013 %
0014 % $Id$
0015   
0016 if nargin < 2
0017   error('Need event specs and sort type');
0018 end
0019 if nargin < 3
0020   downf = 0;
0021 end
0022 
0023 e_s = [evs.e_spec]';
0024 
0025 switch lower(sort_type)
0026  case {'session no', 'session'}
0027   [tmp I] = sortrows(e_s);
0028  case {'event no', 'event'}
0029   [tmp I] = sortrows(e_s, [2 1]);
0030  case {'event name', 'name'}
0031   [tmp I] = sort(evs.names);
0032  otherwise
0033   error(['Crazy sorting too much with ' sort_type]);
0034 end
0035 
0036 if downf, I = flipud(I); end
0037 
0038 evs.names = evs.names(I);
0039 evs.e_spec = evs.e_spec(:, I);
0040 
0041 return

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019