multifunction function to process limit values Limits are beginning, end index pairs for matrix dimensions Inputs action - action string lims - index limits, 2 by number of matrix dimensions type - maybe necessary third argument... Output r - its the output FORMAT s = phiw_lims('to_subs', lims, type) returns subs struct for limits given in lims matrix useful in indexing in subsasgn, subsref FORMAT szs = phiw_lims('size', lims) returns data size for limits given in lims matrix FORMAT dims = phiw_lims('dims', lims) returns data dimensions for limits limits given in lims matrix $Id: phiw_lims.m,v 1.2 2005/06/05 04:42:22 matthewbrett Exp $
0001 function r = phiw_lims(action, lims, type) 0002 % multifunction function to process limit values 0003 % Limits are beginning, end index pairs for matrix dimensions 0004 % 0005 % Inputs 0006 % action - action string 0007 % lims - index limits, 2 by number of matrix dimensions 0008 % type - maybe necessary third argument... 0009 % 0010 % Output 0011 % r - its the output 0012 % 0013 % FORMAT s = phiw_lims('to_subs', lims, type) 0014 % returns subs struct for limits given in lims matrix useful in indexing in 0015 % subsasgn, subsref 0016 % 0017 % FORMAT szs = phiw_lims('size', lims) 0018 % returns data size for limits given in lims matrix 0019 % 0020 % FORMAT dims = phiw_lims('dims', lims) 0021 % returns data dimensions for limits limits given in lims matrix 0022 % 0023 % $Id: phiw_lims.m,v 1.2 2005/06/05 04:42:22 matthewbrett Exp $ 0024 0025 if nargin < 1 0026 error('Need action'); 0027 end 0028 if nargin < 2 0029 error('Need lims'); 0030 end 0031 0032 switch lower(action) 0033 case 'subs' 0034 if nargin < 3, type = '()'; end 0035 [t n] = size(lims); 0036 r = struct('type', type); 0037 for d = 1:n 0038 r.subs{d} = lims(1,d):lims(2,d); 0039 end 0040 case 'size' 0041 if isempty(lims), r = 0; return, end 0042 r = 1; 0043 [t n] = size(lims); 0044 for d = 1:n 0045 r = r * (lims(2,d)-lims(1,d)+1); 0046 end 0047 case 'dims' 0048 if isempty(lims), r = 0; return, end 0049 r = lims(2,:)-lims(1,:)+1; 0050 otherwise 0051 error(['Wild request for ' action]); 0052 end