필터 지우기
필터 지우기

Interpolation of temperature with pressure

조회 수: 8 (최근 30일)
Florian
Florian 2014년 4월 8일
편집: Star Strider 2014년 4월 8일
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

답변 (2개)

Star Strider
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
Florian
Florian 2014년 4월 8일
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 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
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));

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by