0001 function J = calc_jacobian( fwd_model, img)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 if nargin == 1
0028 img= fwd_model;
0029 else
0030 warning('EIDORS:DeprecatedInterface', ...
0031 ['Calling CALC_JACOBIAN with two arguments is deprecated and will cause' ...
0032 ' an error in a future version. First argument ignored.']);
0033 end
0034 ws = warning('query','EIDORS:DeprecatedInterface');
0035 warning off EIDORS:DeprecatedInterface
0036
0037 try
0038 fwd_model= img.fwd_model;
0039 catch
0040 error('CALC_JACOBIAN requires an eidors image structure');
0041 end
0042
0043 fwd_model_check(fwd_model);
0044
0045 if isnumeric(fwd_model.jacobian)
0046 J = fwd_model.jacobian;
0047 else
0048
0049 copt.cache_obj= jacobian_cache_params( fwd_model, img );
0050 copt.fstr = 'jacobian';
0051 try
0052 fwd_model.jacobian = str2func(fwd_model.jacobian);
0053 end
0054 J = eidors_cache(fwd_model.jacobian, {fwd_model, img}, copt);
0055
0056 end
0057
0058 if isfield(fwd_model,'coarse2fine')
0059 c2f= fwd_model.coarse2fine;
0060 if size(J,2)==size(c2f,1)
0061
0062 J=J*c2f;
0063 end
0064 end
0065
0066 warning(ws.state, 'EIDORS:DeprecatedInterface');
0067
0068
0069
0070
0071
0072
0073 function cache_obj= jacobian_cache_params( fwd_model, img );
0074 img = data_mapper(img);
0075 if isfield(img, 'elem_data')
0076 cache_obj = {fwd_model, img.elem_data, img.current_params};
0077 elseif isfield(img, 'node_data')
0078 cache_obj = {fwd_model, img.node_data, img.current_params};
0079 else
0080 error('calc_jacobian: execting elem_data or node_data in image');
0081 end
0082
0083 function fwd_model_check(fmdl)
0084 try; if fmdl.jacobian_dont_check
0085 return
0086 end; end
0087 pp = fwd_model_parameters(fmdl);
0088 if pp.n_elec == 0
0089 error('Cannot calculate Jacobian. No electrodes found.');
0090 end
0091 if pp.n_stim == 0
0092 error('Cannot calculate Jacobian. No stimulation found.');
0093 end
0094 if pp.n_meas == 0
0095 error('Cannot calculate Jacobian. No measurements found.');
0096 end