0001 function num = num_elecs( mdl );
0002
0003
0004
0005
0006
0007 if ischar(mdl) && strcmp(mdl,'UNIT_TEST'); do_unit_test; return; end
0008
0009 if ~isfield(mdl,'type') && isfield(mdl,'elems')
0010 mdl.type = 'fwd_model';
0011 end
0012
0013 switch mdl.type
0014 case 'image'; fmdl = mdl.fwd_model;
0015 case 'inv_model'; fmdl = mdl.fwd_model;
0016 case 'fwd_model'; fmdl = mdl;
0017 otherwise;
0018 error('can''t process model of type %s', mdl.type );
0019 end
0020
0021 if isfield(fmdl,'electrode')
0022 num = length(fmdl.electrode);
0023 else
0024 num = 0;
0025 end
0026
0027
0028 function do_unit_test
0029 mdl = mk_common_model('a2c2',8);
0030 ne = num_elecs( mdl );
0031 unit_test_cmp('test1', ne, 8);
0032
0033 ne = num_elecs( mdl.fwd_model );
0034 unit_test_cmp('test2', ne, 8);
0035
0036 ne = num_elecs( mk_image( mdl ));
0037 unit_test_cmp('test3', ne, 8);
0038
0039 mdl.fwd_model.electrode = struct([]);
0040 ne = num_elecs( mdl );
0041 unit_test_cmp('test4', ne, 0);
0042
0043 mdl.fwd_model = rmfield(mdl.fwd_model,'electrode');
0044 ne = num_elecs( mdl );
0045 unit_test_cmp('test5', ne, 0);
0046
0047 mdl = mk_common_model('n3r2',[16,2]);
0048 ne = num_elecs( mk_image( mdl ));
0049 unit_test_cmp('test6', ne, 32);