elec_rearrange

PURPOSE ^

ELEC_REARRANGE: rearrange electrodes for given pattern

SYNOPSIS ^

function [elec_idx, new_fmdl] = elec_rearrange( pattern, newarrange, fwd_model )

DESCRIPTION ^

 ELEC_REARRANGE: rearrange electrodes for given pattern

 Usage: 
     elec_idx = elec_rearrange( pattern, newarrange );
     fmdl.electrode( elec_idx ) = fmdl.electrode;
   OR;
     [~,new_fmdl] = elec_rearrange( pattern, newarrange, fwd_model );

 pattern    = [Elecs/row, rows]  (eg [16,2])
   or a structure with (p.n_elecs, p.n_layers)

 newarrange = 'square' 
              'zigzag' / 'odd_even' 
              'none' 


 (C) 2017 Andy Adler. License: GPL v2 or v3. $Id: elec_rearrange.m 5663 2017-12-09 21:48:19Z bgrychtol $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [elec_idx, new_fmdl] = elec_rearrange( pattern, newarrange, fwd_model )
0002 % ELEC_REARRANGE: rearrange electrodes for given pattern
0003 %
0004 % Usage:
0005 %     elec_idx = elec_rearrange( pattern, newarrange );
0006 %     fmdl.electrode( elec_idx ) = fmdl.electrode;
0007 %   OR;
0008 %     [~,new_fmdl] = elec_rearrange( pattern, newarrange, fwd_model );
0009 %
0010 % pattern    = [Elecs/row, rows]  (eg [16,2])
0011 %   or a structure with (p.n_elecs, p.n_layers)
0012 %
0013 % newarrange = 'square'
0014 %              'zigzag' / 'odd_even'
0015 %              'none'
0016 %
0017 %
0018 % (C) 2017 Andy Adler. License: GPL v2 or v3. $Id: elec_rearrange.m 5663 2017-12-09 21:48:19Z bgrychtol $
0019 
0020    if ischar(pattern) && strcmp(pattern,'UNIT_TEST'); do_unit_test; return; end
0021 
0022    if isnumeric(pattern)
0023       p.n_elecs = pattern(1);
0024       p.n_layers= pattern(2);
0025    elseif isstruct(pattern)
0026       p = pattern;
0027    else
0028       error('Can''t interpret "pattern" input');
0029    end
0030 
0031    if p.n_layers >= 3;
0032       error('elec_rearrange: can''t interpret n_layers >=2');
0033    end
0034 
0035    idx = reshape(1:(p.n_elecs*p.n_layers),p.n_layers,p.n_elecs);
0036    switch lower(newarrange)
0037      case 'none'; % nothing required
0038      case {'odd_even','zigzag'};
0039         idx = reshape(idx,2,[])';
0040      case 'square'  ;
0041         idx = reshape(idx,2,[])';
0042         idx(2:2:end,:) = fliplr(idx(2:2:end,:));
0043      otherwise;
0044           error('case %s not understood',newarrange);
0045    end
0046   elec_idx = idx(:);
0047 
0048   if nargin >= 3
0049      new_fmdl = fwd_model;
0050      new_fmdl.electrode(elec_idx) = new_fmdl.electrode;
0051   end
0052 
0053 function do_unit_test
0054    sqV = [1,2;4,3;5,6;8,7;9,10;12,11;13,14;16,15]';
0055    oeV = [1,2;3,4;5,6;7,8;9,10;11,12;13,14;15,16]';
0056 
0057 
0058    elec= reshape([1:16],8,2)';
0059    idx = elec_rearrange(size(elec'),'square');
0060    unit_test_cmp('Sq#1 [8,2]', reshape(idx,size(elec'))', sqV);
0061 
0062    idx = elec_rearrange(size(elec'),'odd_even');
0063    unit_test_cmp('OE#1 [8,2]', reshape(idx,size(elec'))', oeV);
0064 
0065    idx = elec_rearrange(size(elec'),'zigZaG');
0066    unit_test_cmp('OE#2 [8,2]', reshape(idx,size(elec'))', oeV);
0067 
0068    idx = elec_rearrange(size(elec'),'none');
0069    unit_test_cmp('OE#2 [8,2]', idx', 1:16);
0070 
0071    p.n_elecs = 8; p.n_layers = 2;
0072    idx = elec_rearrange(p,'square');
0073    idx = reshape(idx,size(elec'))';
0074    unit_test_cmp('Sq#2 [8,2]', idx, sqV);
0075 
0076    elec= [1:32]';
0077    idx = elec_rearrange(size(elec),'square');
0078    idx= reshape(idx,[16,2])';
0079    unit_test_cmp('Sq [16,2]', idx(:,1:8), sqV);
0080 
0081    imdl = mk_common_model('n3r2',[16,2]); fmdl1= imdl.fwd_model;
0082    subplot(221);
0083    idx = elec_rearrange([16,2],'square');
0084    fmdl1.electrode(idx) = fmdl1.electrode;
0085    show_fem_enhanced(fmdl1,[0,1]);
0086    view(10,82);
0087 
0088    subplot(222);
0089    [~,fmdl2] = elec_rearrange([16,2],'square', imdl.fwd_model);
0090    show_fem_enhanced(fmdl2,[0,1]);
0091    view(10,82);
0092 
0093    unit_test_cmp('fmdl#1', [fmdl1.electrode([5,9]).nodes], [156 157 219 220 128 129 191 192]);
0094    unit_test_cmp('fmdl#2', fmdl1.electrode, fmdl2.electrode)

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005