Interpolation of temperature with pressure
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Star Strider
el 8 de Abr. de 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 comentarios
Star Strider
el 8 de Abr. de 2014
Editada: Star Strider
el 8 de Abr. de 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.)
Kelly Kearney
el 8 de Abr. de 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));
0 comentarios
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!