Interpolation/Align two nonuniform grid in same time and space and convert it to a uniform Grid where both values are known at the same point.

7 views (last 30 days)
Hello everyone,
I am not the professinal with Matlab and I have a problem to solve. I got a commercial program, which gives me the values of E-field and W/kg for a phantom.
When I export the values so I can use it in Matlab, the two coordinate systems doesn't fit to each other like one to one. I have made an illustration in 2D but it is a 3D problem tho.
It is two non-uniform grids, but it is in the same space
In my case I got two coordinate system, which you can see down below: The distance from each pixel/voxel, just like the E-field grid is between 1.9mm-0.9mm. I need to make the grid uniform and change the distance to 2mm for each pixel/voxel. And I have to know the E and Kg/W at the midpoint because I need them for further calculations. The E-field value is a complex number, which include real and imaginary numbers but we can forget about that for now.
So when I got my data, I got the x,y,z coordinates which are vectors and an E-value and a S-value, which fits with the coordinates as a n*m*l (matrix) since we need 3 positions to place the point.
if true
% code
load('E1.mat')
Ex=x_axis*1000; % 195x1
Ey=y_axis*1000; % 190x1
Ez=z_axis*1000; % 181x1
E %195x190x191
load('SAR1.mat')
KgWx=x_axis*1000; % 194x1
KgWy=y_axis*1000; % 189x1
KgWz=z_axis*1000; % 180x1
KgW %194x189x180
% Creating a mesh
[Exx, Eyy, Ezz] = meshgrid(Ey,Ex,Ez);
[KgWxx, KgWyy, KgWzz] = meshgrid(KgWy,KgWx,KgWz);
% Making a meshgrid with a spacing of 2 making more points
[Exx0, Eyy0, Ezz0] = meshgrid(min(Ex):2:max(Ex), min(Ey):2:max(Ey), min(Ez):2:max(Ez));
[KgWxx0, KgWyy0, KgWzz0] = meshgrid(min(KgWx):2:max(KgWx), min(KgWy):2:max(KgWy), min(KgWz):2:max(KgWz));
% As I said I also got my E-value and kgW-value corresponding to the x,y & z, so I though I could regard E & kgW as *v* for griddata(x,y,z, *v*,xq,yq,zq);
% The griddata function doesn't work somehow...
%vq = griddata(Exx,Eyy,Ezz,E,Exx0,Eyy0,Ezz0);
end
But I couldn't get further than that.... and I don't know to to combine the grids so they overlap each other.
It will be a great help if someone got an idea how to solve it, and thank you for your time! :)

Accepted Answer

Matt J
Matt J on 2 May 2016
Edited: Matt J on 2 May 2016
Since the original samples of both E and KgW are gridded, it sounds like you could just use do gridded interpolation twice. The only thing you need to do is specify different initial grid vectors {ne,me} for E and {nkgw,mgw} for KgW:
Fe=griddedInterpolant({ne,me},E)
Fkgw=griddedInterpolant({nkgw,mgw},KgW);
E_resamp=Fe({nCommon,mCommon},E);
KgW_resamp= Fkgw({nCommon,mCommon},E);
and a common set of grid vectors {nCommon,mCommon} for the target sampling.
  7 Comments
Matt J
Matt J on 5 May 2016
Edited: Matt J on 5 May 2016
So right now it is interpolated but it is still non-uniform. So I can just make it uniform after this right?
Yes, but I wouldn't do it by interpolating twice. In other words, there is no need to first resample KgW onto a common grid with E and then resample again to make the grids uniform. That will compound interpolation/resampling error. Just resample each array separately onto the final uniform grid that you want, like I suggested in my original answer.
Nick Yin Larsen
Nick Yin Larsen on 6 May 2016
Great! - everything is working now! Thank you for your time Matt!
And with the help from you it turned out to be:
Maybe it is hard to see here but now it is a uniform grid :D

Sign in to comment.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!