Interpolate to fill missing values in a temperature Matrix by considering the altitude (stored in a separate matrix)
Mostrar comentarios más antiguos
Dear all,
I have got a matrix with temperatures (let's call it T), and a matrix with altitudes (let's call it Z). They're both 150x150.
T contains some missing values that I need to fill.
Rather than filling it with a basic linear interpolation, I need to fill it taking into account the altitude (Z).
Could you please suggest a code to fill the missing values in T weighted on Z?
Thanks a lot!
2 comentarios
dpb
el 30 de Abr. de 2023
With no more to go on than that, one would presume the location of the two already contains the variations in Z into account by position in the array. It wouldn't seem much else able to do other than interp2 around each missing location; unless, of course, the elevatioins in the other array are not representive of the location they occupy in the array -- in which case it wouldn't seem there would be sufficient data/knowledge available to do anything more, anyway, either.
Mathieu NOE
el 2 de Mayo de 2023
maybe with some data it would help figure out a good solution ...
Respuestas (1)
What exactly does "missing" mean to you? You can't have "holes" in the matrix. The values must either be nan, 0, or some other value.
help interp2
5 comentarios
Mathieu NOE
el 4 de Mayo de 2023
if the relationship is monotonic betweenelements of T and Z , even they are presented as 2D arrays, the problem is simply a 1D interpolation, what I did below :
i modified a bit the data so I didn't have to deal with uniqueness (and have more unique data points)
% For instance, my T matrix is:
T=[1,4.95,1.2;
4.5,NaN,4.4;
1.3,5,1.4];
% and the associated Z matrix is:
Z=[300,110,290;
120,200,130;
250,100,220];
[Trow,ind] = sort(T(:));
idn = ~isnan(Trow);
Trow= Trow(idn);
Zrow= Z(:)
Zrow= Zrow(ind);
Zrow= Zrow(idn);
% sort Z elements in ascending order
[Zrow,ind] = sort(Zrow);
Trow= Trow(ind);
% plot relationship between T and Z
plot(Zrow,Trow);
% find interpolated value to replace NaN T element
T_nan = interp1(Zrow,Trow,Z(isnan(T)));
Simone A.
el 6 de Mayo de 2023
Mathieu NOE
el 7 de Mayo de 2023
hello again
before you do the interpolation with interp1 , you have to make sure that the data (Zrow,Trow) are unique
use unique to remove duplicates
dpb
el 7 de Mayo de 2023
"...with interp1 , you have to make sure that the data (Zrow,Trow) are unique"
The functional also cannot be double-valued, so if your data follow the terrain up and down, that doesn't work, either.
Categorías
Más información sobre Interpolation of 2-D Selections in 3-D Grids en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!