return dimension permute shifts needed for wt/iwt routines FORMAT [shifts, end_shift] = wt_dim_shifts(p_dims) Inputs p_dims - flags, one for each dimension, non-zero if dimension is to be (wt, iwt) processed sz - size of matrix to be processed (needed to identify row vectors) Outputs shifts - values, one for each non-zero value of p_dims, giving how many extra dimensions to shift to get the current (p_dim) dimension to be X (columns) end_shift - how many shifts right to get from last processed dimension back to original matrix orientation For example, if processing all 3 dimensions of a 3D matrix, we will need to specify 4 shifts. When processing the first (X) dimension, we do not have to do a shift (shift(1) = 0). For Y we will need to shift Y to X (shift(2) = -1). For Z, we further need to shift Z to X: shift(3) = -1; Last, to shift back to where we started (X back to X) we need an end shift (end_shift = -1). This will result in the following permutes, in the wt/iwt routines: x1 = permute(x, [1 2 3]); % shift(1) of 0 x2 = permute(x1, [2 3 1]); % Y->X; shift(2) of -1 x3 = permute(x2, [2 3 1]); % Z->X; shift(3) of -1 x = permute(x3, [2 3 1]); % X->X; end_shift of -1 $Id: wt_dim_shifts.m,v 1.1 2004/09/26 04:00:24 matthewbrett Exp $
0001 function [shifts, end_shift] = wt_dim_shifts(p_dims, sz) 0002 % return dimension permute shifts needed for wt/iwt routines 0003 % FORMAT [shifts, end_shift] = wt_dim_shifts(p_dims) 0004 % 0005 % Inputs 0006 % 0007 % p_dims - flags, one for each dimension, non-zero if dimension is 0008 % to be (wt, iwt) processed 0009 % sz - size of matrix to be processed 0010 % (needed to identify row vectors) 0011 % 0012 % Outputs 0013 % 0014 % shifts - values, one for each non-zero value of p_dims, giving how 0015 % many extra dimensions to shift to get the current (p_dim) 0016 % dimension to be X (columns) 0017 % 0018 % end_shift - how many shifts right to get from last processed 0019 % dimension back to original matrix orientation 0020 % 0021 % For example, if processing all 3 dimensions of a 3D matrix, we will need 0022 % to specify 4 shifts. When processing the first (X) dimension, we do not 0023 % have to do a shift (shift(1) = 0). For Y we will need to shift Y to X 0024 % (shift(2) = -1). For Z, we further need to shift Z to X: shift(3) = -1; 0025 % Last, to shift back to where we started (X back to X) we need an end shift 0026 % (end_shift = -1). This will result in the following permutes, in the 0027 % wt/iwt routines: 0028 % 0029 % x1 = permute(x, [1 2 3]); % shift(1) of 0 0030 % x2 = permute(x1, [2 3 1]); % Y->X; shift(2) of -1 0031 % x3 = permute(x2, [2 3 1]); % Z->X; shift(3) of -1 0032 % x = permute(x3, [2 3 1]); % X->X; end_shift of -1 0033 % 0034 % $Id: wt_dim_shifts.m,v 1.1 2004/09/26 04:00:24 matthewbrett Exp $ 0035 0036 n_dims = length(p_dims); 0037 fpd = find(p_dims); 0038 0039 % First check for situations where we do not have to do any shifts 0040 if all(fpd == 1) | ... % only processing X dimension 0041 (n_dims == 2 & sz(1) == 1) % row vector 0042 shifts = zeros(1, sum(p_dims)); 0043 end_shift = 0; 0044 else % we do have to do shifts 0045 shifts = diff([1 fpd n_dims+1]) * -1; 0046 end_shift = shifts(end); 0047 shifts = shifts(1:n_dims); 0048 end 0049