0001 function memb_frac = elem_select( fmdl, select_fcn )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 if isstr(fmdl) && strcmp(fmdl,'UNIT_TEST'); do_unit_test; return; end
0025
0026
0027
0028 dims = size(fmdl.nodes,2);
0029 interp_no = 6 - dims;
0030 try
0031 interp_no = fmdl.elem_select.interp_no;
0032 end
0033
0034 pts = interp_mesh( fmdl, interp_no );
0035 x = squeeze(pts(:,1,:));
0036 y = squeeze(pts(:,2,:));
0037 if dims ==2;
0038 z = 0*x;
0039 else
0040 z = squeeze(pts(:,3,:));
0041 end
0042 if ~iscell(select_fcn)
0043
0044 memb_frac = mean( feval(select_fcn,x,y,z), 2);
0045 else
0046
0047 memb_val = ones(size(x));
0048 for i = 1:numel(select_fcn)
0049 memb_val = memb_val .* feval(select_fcn{i},x,y,z);
0050 end
0051 memb_frac = mean(memb_val,2);
0052 end
0053
0054
0055 function do_unit_test;
0056 imdl = mk_common_model('a2c2',8);
0057 select_fcn = inline('(x-0.2).^2+(y-0.5).^2<0.2^2','x','y','z');
0058 memb_frac = elem_select( imdl.fwd_model, select_fcn);
0059 unit_test_cmp('a2c2',find(memb_frac), [5, 10,18,26,27]');
0060
0061 select_fcn2= inline('y<0.4','x','y','z');
0062 memb_frac = elem_select( imdl.fwd_model, {select_fcn,select_fcn2});
0063 unit_test_cmp('a2c2 (2fcns)',find(memb_frac), [5, 10,18,27]');
0064
0065 imdl = mk_common_model('n3r2',8);
0066 select_fcn = inline('(x-0.2).^2+(y-0.5).^2 + (z-1).^2<0.1^2','x','y','z');
0067 memb_frac = elem_select( imdl.fwd_model, select_fcn);
0068 unit_test_cmp('n3r2',find(memb_frac), [156 159 162 168 431 434 437 503]');
0069
0070
0071
0072