Mercurial > repos > public > sbplib
annotate +grid/evalOn.m @ 274:ac8e00883986 feature/beams
Fixed a comment.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 06 Sep 2016 15:54:45 +0200 |
parents | 0e56192f6459 |
children | 3ea2ae2a3d15 |
rev | line source |
---|---|
157 | 1 % Takes a funciton and evaluates it on a grid to return a grid function in the |
2 % form of a (n*k)x1 vector, where n is the number of grid points and k is the | |
3 % number of components of the function. | |
4 % g -- Grid to evaluate on. | |
5 % func -- Function to evaluate. May be a function handle or a constant. If | |
6 % it is a vector value it has to be provided as a column vector, | |
7 function gf = evalOn(g, func) | |
8 if ~isa(func, 'function_handle') | |
9 % We should have a constant. | |
10 if size(func,2) ~= 1 | |
11 error('grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector') | |
12 end | |
13 | |
14 gf = repmat(func,[g.N, 1]); | |
15 return | |
16 end | |
17 % func should now be a function_handle | |
18 | |
19 % Get coordinates and convert to cell array for easier use as a parameter | |
20 x = g.points(); | |
21 X = {}; | |
22 for i = 1:size(x, 2) | |
23 X{i} = x(:,i); | |
24 end | |
25 | |
26 % Find the number of components | |
27 x0 = num2cell(x(1,:)); | |
28 f0 = func(x0{:}); | |
29 k = length(f0); | |
30 | |
31 if size(f0,2) ~= 1 | |
32 error('grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector') | |
33 end | |
34 | |
35 gf = func(X{:}); | |
274 | 36 if k > 1 % Reorder so that vectors sit together. |
171
0e56192f6459
Made evalOn a bit clearer.
Jonatan Werpers <jonatan@werpers.com>
parents:
157
diff
changeset
|
37 gf = reshape(reshape(gf, [g.N, k])', [g.N*k, 1]); |
0e56192f6459
Made evalOn a bit clearer.
Jonatan Werpers <jonatan@werpers.com>
parents:
157
diff
changeset
|
38 end |
157 | 39 end |