Interpolation of temperature with pressure
4 ビュー (過去 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!