Interpolate to find values at particular points from a 45x28 matrix

4 views (last 30 days)
Hi,
I currently have a 45x28 matrix [P] which is some pressures that I have measured experimentally over a single flat plane. The coordinates of the pressures in the x and y direction are [X,Y].
I have a two matrixes of x and y coordinates [x] and [y] respectively which I need to find the pressures for by interpolating from my pressure matrix as the exact x and y coordinates do not match my X and Y coordinates.
Can anyone please shed some light?
Thank you in advance.
  1 Comment
Charlie
Charlie on 15 Feb 2012
I have included my code in an answer below which is not working and some more information about the data I am working with.
If anyone has any suggestions I would be extremely grateful. I have been working on this for days :S

Sign in to comment.

Answers (2)

Matt Tearle
Matt Tearle on 10 Feb 2012
Sounds like a job for TriScatteredInterp!
F = TriScatteredInterp(X,Y,P);
p = F(x,y);
Are X and Y matrices (same dimensions as P)? If not, you'll want some meshgrid action as well.
EDIT TO ADD: Sorry, I need to learn to read, sometimes. If you currently have data on a regular (coarse grid) and you want to move to a finer grid, use interp2. If you have scattered data, use TriScatteredInterp. Given that you did say your pressures are in a matrix P, it sounds like they're already on a regular X - Y grid. (So use interp2.)
p = interp2(X,Y,P,x,y);
surf(x,y,p)
EDIT TO ADD #2: Obviously I don't have your data files, but try this:
a = 0;
b = -0.39;
r = 0.2;
t = 0:step:(9*step);
ycirc = a + r*cos(t);
zcirc = b + r*sin(t);
[Ycirc,Zcirc]= meshgrid(ycirc,zcirc);
F = TriScatteredInterp(Y11(:),Z11(:),P11(:));
interp = F(Ycirc,Zcirc);
EDIT TO ADD #3(!): Do you actually want to meshgrid ycirc and zcirc? The end result is a rectangular grid with unequal spacing (but equal in polar coords). You can interpolate just onto a circle, if you want:
t = 0:step:(9*step);
ycirc = a + r*cos(t);
zcirc = b + r*sin(t);
F = TriScatteredInterp(Y11(:),Z11(:),P11(:));
interp = F(ycirc,zcirc);
surf(Y11,Z11,P11)
hold on
plot3(ycirc,zcirc,interp,'o')

Charlie
Charlie on 15 Feb 2012
Hi all,
Thank you for your help so far. I am still struggling to get my code to work.
It should be noted that Y11 and Z11 are my X and Y axis coordinates which meshes with my P11 which is the data I wish to interpolate. Y11 and Z11 is not regularly spaced and starts at a negative real number.
The first bit of code finds the coordinates I need to interpolate the data at which is 10 points around a circle. However I can not get the interp2 function to work for me.
My code I have written is below and any help would be greatly appreciated:
P11 = importdata('windtunneltestPx=250.txt')*6894.757
z11 = importdata('windtunneltestZx=250.txt')/1000
y11 = importdata('windtunneltestYx=250.txt')/100
[Z11,Y11]=meshgrid(z11,y11);
step = (2*pi)/10
a = 0
b = -0.39
r = 0.2
t(1) = 0 for i=1:10
t(i+1) = t(i)+step
ycirc(i)=a+r*cos(t(i))
zcirc(i)=b+r*sin(t(i))
end
[Ycirc,Zcirc]= meshgrid(ycirc,zcirc);
interp = interp2(Y11,Z11,P11,Ycirc,Zcirc)

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!