cavereaper
cavereaper

Reputation: 41

Matlab interpolation of 4D scattered data

We have a 195x4 (double) matrix: A=[X Y Z temp], when ploted with scatter3(A(:,1), A(:,2), A(:,3),30, A(:,4), 'filled' ) gives something like this: enter image description here

Now we want to generate a 'cube' colored with the interpolation of the temp=A(:,4) vector data. So far we have tried interp3

% Base Grid
[Xm Ym Zm] = meshgrid(A(:,1), A(:,2), A(:,3)); 
% Grid Refinement
[Xq,Yq,Zq] = meshgrid(xmin:dx:xmax, ymin:dy:ymax, zmin:dz:zmax);
Aq = interp3(Xm,Ym,Zm,A(:,4),Xq,Yq,Zq);

Returns the following error:

Error using griddedInterpolant
The number of input coordinate arrays does not equal the number of dimensions
(NDIMS) of these arrays.

Error in interp3 (line 144)
            F = griddedInterpolant(X, Y, Z, V, method,extrap);

Error in PDGEM_MT (line 112)
Aq = interp3(Xm,Ym,Zm,A(:,4),Xq,Yq,Zq);

So I think, may be a bad implementation and/or a wrong interpretation of the problem. How to generate a 'cube'of that space colored with the volume interpolation of A(:,4)?

Thanks in advance.

Upvotes: 1

Views: 1326

Answers (1)

user7431005
user7431005

Reputation: 4539

You have an scattered dataset.

interp3 does only work if your data points are in meshgrid format read this. The short description of this function is Interpolation for 3-D gridded data in meshgrid format

Instead you can use griddata which works for scattered data read this. The short description is Interpolate 2-D or 3-D scattered data.

Example:

X = rand(100,1);
Y = rand(100,1);
Z = rand(100,1);
C = rand(100,1);

figure
scatter3(X, Y, Z,30, C, 'filled' )

[Xm, Ym, Zm] = meshgrid(min(X):.01:max(X), min(Y):.01:max(Y), min(Z):.01:max(Z)); 

Cm = griddata(X,Y,Z,C,Xm,Ym,Zm);

figure
scatter3(Xm(:), Ym(:), Zm(:), 30, Cm(:), 'filled' )

Data points: data

Interpolated: gridded

Upvotes: 2

Related Questions