num_elems

PURPOSE ^

NUM_ELEMS: number of elemnts in a (fwd or inv model or image)

SYNOPSIS ^

function num = num_elems( mdl );

DESCRIPTION ^

 NUM_ELEMS: number of elemnts in a (fwd or inv model or image)
 num_elems = num_elems( mdl );

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function num = num_elems( mdl );
0002 % NUM_ELEMS: number of elemnts in a (fwd or inv model or image)
0003 % num_elems = num_elems( mdl );
0004 
0005 % $Id: num_elems.html 2819 2011-09-07 16:43:11Z aadler $
0006 
0007 if isstr(mdl) && strcmp(mdl,'UNIT_TEST'); do_unit_test; return; end
0008 
0009 if ~isfield(mdl,'type') && isfield(mdl,'elems') % Set default for this case
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 num = size(fmdl.elems,1);
0022 
0023 
0024 function do_unit_test
0025    mdl = mk_common_model('a2c2',8);
0026    ne = num_elems( mdl );
0027    ok='fail'; if ne==64; ok='ok'; end; fprintf('test1: %10s\n',ok);
0028 
0029    ne = num_elems( mdl.fwd_model );
0030    ok='fail'; if ne==64; ok='ok'; end; fprintf('test2: %10s\n',ok);
0031 
0032    ne = num_elems( mk_image( mdl ));
0033    ok='fail'; if ne==64; ok='ok'; end; fprintf('test3: %10s\n',ok);
0034 
0035    mdl = mk_common_model('n3r2',16);
0036    ne = num_elems( mk_image( mdl ));
0037    ok='fail'; if ne==828; ok='ok'; end; fprintf('test4: %10s\n',ok);

Generated on Tue 09-Aug-2011 11:38:31 by m2html © 2005