structtimes_jd

PURPOSE ^

SYNOPSIS ^

function [s,fields] = structtimes_jd(s,a)

DESCRIPTION ^

 This function multiplies all fields from the structure s by the scalar a
 if applicable, in which case the field is return in 'fields'.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [s,fields] = structtimes_jd(s,a)
0002 %
0003 % This function multiplies all fields from the structure s by the scalar a
0004 % if applicable, in which case the field is return in 'fields'.
0005 %
0006 if nargin < 2,
0007     a = 1;
0008 elseif ~isnumeric(a),
0009     error('Numerical array or scalar is requested as second argument in structtimes_jd');
0010 end
0011 if nargin < 1 || ~isstruct(s),
0012     error('Structure is requested as first argument in structtimes_jd');
0013 end
0014 %
0015 fnames = fieldnames(s);
0016 %
0017 nfields = length(fnames);
0018 %
0019 flag = false(1,nfields);
0020 %
0021 sa = size(a);
0022 %
0023 for ifield = 1:nfields,
0024     %
0025     fname = fnames{ifield};
0026     %
0027     if isnumeric(s.(fname)),
0028         sf = size(s.(fname));
0029         %
0030         if isscalar(sa) || isscalar(sf) || (length(sf) == length(sa) && all(sf == sa)),
0031             s.(fname) = s.(fname).*a;
0032             flag(ifield) = true;
0033         end
0034     end
0035     %
0036 end
0037 %
0038 fields = fnames(flag);

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.