Home > marsbar > @marsy > region_size.m

region_size

PURPOSE ^

method to get size of specified region data

SYNOPSIS ^

function [m,n] = region_size(o, r_no, dim)

DESCRIPTION ^

 method to get size of specified region data
 FORMAT [m,n] = region_size(o, r_no, dim)

 Input
 o        - marsy object
 r_no     - region number OR vector of region numbers 
            OR 'all' ['all' is default] 
 dim      - [optional] dimension size to return

 Output
 m        - as for matlab SIZE call
 n        -

 e.g 
 % returns total number of timepoints (sz(1) and samples (sz(2) 
 % in all regions
 sz = region_size(o); 
 % same thing
 sz = region_size(o, 'all');
 % number of samples in region 2
 n = region_size(o, 2, 2);

 $Id$ 

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [m,n] = region_size(o, r_no, dim)
0002 % method to get size of specified region data
0003 % FORMAT [m,n] = region_size(o, r_no, dim)
0004 %
0005 % Input
0006 % o        - marsy object
0007 % r_no     - region number OR vector of region numbers
0008 %            OR 'all' ['all' is default]
0009 % dim      - [optional] dimension size to return
0010 %
0011 % Output
0012 % m        - as for matlab SIZE call
0013 % n        -
0014 %
0015 % e.g
0016 % % returns total number of timepoints (sz(1) and samples (sz(2)
0017 % % in all regions
0018 % sz = region_size(o);
0019 % % same thing
0020 % sz = region_size(o, 'all');
0021 % % number of samples in region 2
0022 % n = region_size(o, 2, 2);
0023 %
0024 % $Id$
0025 
0026 r = n_regions(o);
0027 if nargin < 2
0028   r_no = 'all';
0029 end
0030 if ischar(r_no)
0031   if strcmp(lower(r_no), 'all')
0032     r_no = 1:r;
0033   else
0034     error(['Surprise request of ' r_no]);
0035   end
0036 else
0037   if any(r_no > r | r_no < 1)
0038     error('Region number(s) out of range');
0039   end
0040 end
0041 
0042 st = y_struct(o);
0043 r_f = isfield(st, 'regions');
0044 y_f = isfield(st, 'Y');
0045 
0046 if ~r_f & ~y_f
0047   error('No information for region data size');
0048 end
0049 
0050 n = 0;
0051 for r = r_no
0052   r_st = [];
0053   if r_f, r_st = st.regions{r}; end
0054   if isfield(r_st, 'Y')
0055     [m n_r] = size(r_st.Y);
0056     n = n + n_r;
0057   elseif y_f    
0058     m = size(st.Y, 1);
0059     n = n + 1;
0060   else
0061     error('No data to get size for region');
0062   end
0063 end
0064 
0065 if nargin < 3
0066   if nargout < 2
0067     m = [m n];
0068   end
0069 else  
0070   if dim == 2
0071     m = n;
0072   elseif dim > 2
0073     m = ((m+n) > 0);
0074   end
0075 end

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