diff +grid/evalOn.m @ 425:e56dbd9e4196 feature/grids

Merge feature/beams
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 07 Feb 2017 16:09:02 +0100
parents 4c3f55a628c8
children ce44af8d7dd1
line wrap: on
line diff
--- a/+grid/evalOn.m	Tue Feb 07 15:47:51 2017 +0100
+++ b/+grid/evalOn.m	Tue Feb 07 16:09:02 2017 +0100
@@ -1,4 +1,4 @@
-% Takes a funciton and evaluates it on a grid to return a grid function in the
+% Takes a function and evaluates it on a grid to return a grid function in the
 % form of a (n*k)x1 vector, where n is the number of grid points and k is the
 % number of components of the function.
 %      g -- Grid to evaluate on.
@@ -16,15 +16,18 @@
     end
     % func should now be a function_handle
 
-    % Get coordinates and convert to cell array for easier use as a parameter
-    x = g.points();
-    X = {};
-    for i = 1:size(x, 2)
-        X{i} = x(:,i);
+    if g.D ~= nargin(func)
+        g.D
+        nargin(func)
+        error('grid:evalOn:WrongNumberOfInputs', 'The number of inputs of the function must match the dimension of the domain.')
     end
 
+
+    % Get coordinates and convert to cell array for easier use as a parameter
+    x = num2cell(g.points());
+
     % Find the number of components
-    x0 = num2cell(x(1,:));
+    x0 = x(1,:);
     f0 = func(x0{:});
     k = length(f0);
 
@@ -32,8 +35,11 @@
         error('grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector')
     end
 
-    gf = func(X{:});
-    if  k > 1  % Reorder so that componets sits together.
-        gf = reshape(reshape(gf, [g.N, k])', [g.N*k, 1]);
+    gf = zeros(g.N*k, 1);
+    % keyboard
+    for i = 1:g.N
+        % (1 + (i-1)*k):(i*k)
+        % func(x{i,:})
+        gf((1 + (i-1)*k):(i*k)) = func(x{i,:});
     end
 end
\ No newline at end of file