Interpolation of temperature with pressure
5 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
Star Strider
2014-4-8
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 个评论
Star Strider
2014-4-8
编辑:Star Strider
2014-4-8
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.)
Kelly Kearney
2014-4-8
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));
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!