Mercurial > repos > public > sbplib
changeset 626:da30d3bbeea6 feature/grids
Avoid eval
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 20 Oct 2017 23:13:43 +0200 |
parents | 55e6267be117 |
children | c602fe0a778c |
files | +grid/evalOn.m |
diffstat | 1 files changed, 4 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
diff -r 55e6267be117 -r da30d3bbeea6 +grid/evalOn.m --- a/+grid/evalOn.m Fri Oct 20 23:07:03 2017 +0200 +++ b/+grid/evalOn.m Fri Oct 20 23:13:43 2017 +0200 @@ -15,20 +15,10 @@ % func should now be a function_handle assert(g.D == nargin(func),'grid:evalOn:WrongNumberOfInputs', 'The number of inputs of the function must match the dimension of the domain.') - x = g.points(); + x = num2cell(g.points(),1); k = numberOfComponents(func, x); - % Evaluate gf = func(x(:,1),x(:,2),...,x(:,dim)); - if(g.D == 1) - gf = func(x); - else - eval_str = 'gf = func(x(:,1)'; - for i = 2:g.D - eval_str = [eval_str, sprintf(',x(:,%d)',i)]; - end - eval_str = [eval_str, ');']; - eval(eval_str); - end + gf = func(x{:}); % Reorganize gf gf_temp = gf; @@ -40,25 +30,9 @@ % Find the number of vector components of func function k = numberOfComponents(func, x) - if size(x,1) ~= 0 - x0 = x(1,:); - else - x0 = num2cell(ones(1,size(x,2))); - end + x0 = num2cell(ones(1,size(x,2))); - dim = length(x0); - % Evaluate f0 = func(x0(1),x0(2),...,x0(dim)); - if(dim == 1) - f0 = func(x0); - else - eval_str = 'f0 = func(x0(1)'; - for i = 2:dim - eval_str = [eval_str, sprintf(',x0(%d)',i)]; - end - eval_str = [eval_str, ');']; - eval(eval_str); - end - + f0 = func(x0{:}); % k = number of components k = length(f0);