1% Derive fractional indices on a regular grid.
2%
3% I = localize_regular_grid(xi,mask,x)
4%
5% Derive fractional indices where xi are the points to localize in the
6% regular grid x (constant increment in all dimension).
7% The output I is an n-by-m array where n number of dimensions and m number of
8% observations
9
10function I = localize_regular_grid(xi,mask,x)
11
12x = cat_cell_array(x);
13xi = cat_cell_array(xi);
14
15% m is the number of arbitrarily distributed observations
16tmp = size(xi);
17mi = prod(tmp(1:end-1));
18
19% sz is the size of the grid
20tmp = size(x);
21sz = tmp(1:end-1);
22m = prod(sz);
23
24% n dimension of the problem
25n = tmp(end);
26
27xi = reshape(xi,mi,n);
28
29scale = [1 cumprod(sz(1:end-1))];
30
31A = zeros(n,n);
32
33x0 = x([0:n-1]' * m +1)';
34
35E = eye(n);
36
37I = zeros(n,size(xi,1));
38
39for i=1:n
40  I(i,:) = (xi(:,i) - x0(i));
41
42  % linear index of element (2,1,1,...,:),
43  % (1,2,1,...,:), (1,1,2,...,:) ...
44
45  l = scale*E(:,i) + [0:n-1]' * m +1;
46  A(i,:) = x(l)- x0(:);
47end
48
49
50I = A \ I + 1;
51
52% LocalWords:  indices sz
53
54% Copyright (C) 2014 Alexander Barth <a.barth@ulg.ac.be>
55%
56% This program is free software; you can redistribute it and/or modify it under
57% the terms of the GNU General Public License as published by the Free Software
58% Foundation; either version 2 of the License, or (at your option) any later
59% version.
60%
61% This program is distributed in the hope that it will be useful, but WITHOUT
62% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
63% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
64% details.
65%
66% You should have received a copy of the GNU General Public License along with
67% this program; if not, see <http://www.gnu.org/licenses/>.
68