Interpolation of temperature with pressure

12 views (last 30 days)
Florian
Florian on 8 Apr 2014
Edited: Star Strider on 8 Apr 2014
Hi all,
as a newbie in Matlab, I've got a simple problem :
1) I have two dataset of pressure and temperature which both have a length of 1000
2) There are some missing data in my temperature profile, I'd like to interpolate around these missing values
3) I use interp1(temperature,pressure) -> it doesn't interpolate (no error message)
Why ?
Thank you for your help ! Florian

Answers (2)

Star Strider
Star Strider on 8 Apr 2014
You have to tell it at what value of what variable you want to interpolate your data. (Your call to interp1 needs a third argument.)
  2 Comments
Florian
Florian on 8 Apr 2014
I agree but missing values are represented by NaN and when I try to interpolate like :
interp1(temperature,entire_file_that_contain_temperature&pressure,pressure)
I get :
Error using griddedInterpolant
The coordinates of the input points must be finite values; Inf and NaN are not permitted.
Star Strider
Star Strider on 8 Apr 2014
Edited: Star Strider on 8 Apr 2014
I don’t know what your data look like, so I generated my own. You may have to adapt this to your situation. You can trace it through to see how it functions.
This seems to be a solution:
% Create data —
x = 0:0.1:2*pi;
y = sin(x);
% Create NaNs in data —
yn = y;
xn = x;
xn(5:5:end) = NaN;
yn(5:5:end) = NaN;
% Convert NaNs to missing values —
xm = xn;
ym = yn;
ym(isnan(ym)) = [];
xm(isnan(xm)) = [];
% Find indices of NaNs and interpolate for missing ‘x’ values —
ixn = find(isnan(xn));
for k1 = 1:size(ixn,2)
ixr = [xn(ixn(k1)-1) xn(ixn(k1)+1)];
xi(k1) = mean(ixr);
end
% Use interpolated ‘x’ values to interpolate missing ‘y’ values —
yi = interp1(xm, ym, xi);
figure(1)
plot(xn, yn, 'ob')
hold on
plot(xi, yi, '+r')
hold off
grid
(Apologise for the delay. Out for a bit on errands.)

Sign in to comment.


Kelly Kearney
Kelly Kearney on 8 Apr 2014
Assuming temp and pressure are your vectors, you need to use the non-missing values to interpolate the missing ones:
ismissing = isnan(temp);
temp(ismissing) = interp1(pressure(~ismissing), temp(~ismissing), pressure(ismissing));

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!