From: Florian on
Hi everyone, let me explain my problem with an example

% A two dimensional example:
% Let's assume you have the following two dimensional grid data points
X = [1 6;3 7;5 2;8 1;10 0];

% In order to use griddatan for interpolation I need to convert these into a monotonously spaced grid like:
[x1,x2] = ndgrid( min((X(:,1))):1:max(X(:,1)), min((X(:,2))):1:max(X(:,2)) );

% The following xi is then used in griddatan
xi = [x1(:) y2(:)];

Generally speaking I need a code which automatically splits up X in N subvectors for N dimensions, passes them to ndgrid and also generates x2-xn automatically to produce xi.

How can I automate this if I only know that my data has N dimensions (X has N columns)?

thanks for your help,
Florian
From: Matt on
"Florian" <flowwiththeflo(a)hotmail.com> wrote in message <hejpbt$s1b$1(a)fred.mathworks.com>...
> Hi everyone, let me explain my problem with an example
>
> % A two dimensional example:
> % Let's assume you have the following two dimensional grid data points
> X = [1 6;3 7;5 2;8 1;10 0];
>
> % In order to use griddatan for interpolation I need to convert these into a monotonously spaced grid like:
> [x1,x2] = ndgrid( min((X(:,1))):1:max(X(:,1)), min((X(:,2))):1:max(X(:,2)) );
>
> % The following xi is then used in griddatan
> xi = [x1(:) y2(:)];
>
> Generally speaking I need a code which automatically splits up X in N subvectors for N dimensions, passes them to ndgrid and also generates x2-xn automatically to produce xi.
>
> How can I automate this if I only know that my data has N dimensions (X has N columns)?

Something like the following:

N=size(X,2);

Xmins=min(X,[],1);
Xmaxs=max(X,[],1);

for ii=1:N
ndgridArgs{ii}=Xmins(ii):Xmaxs(ii);
end

[xi{1:N}]=ndgrid( ndgridArgs{:} );

xi=cat(N+1, xi{:});

xi=reshape(xi,[],N);
 | 
Pages: 1
Prev: Contrast Slider
Next: interp3