How to link lat/lon to a variable based on time?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have two sets of data taken simultaneously. Dataset A includes a time vector, and a corresponding matrix of lat/lon values taken at those times. Dataset B has a different time vector, and corresponding reflectance data.
I want to link the lat/lon from Dataset A to the reflectance data from Dataset B Since I have time for both datasets, I was thinking I could interpolate the lat/lon values from Dataset A to new lat/lon values that match the Dataset B time, but am struggling. Does anyone know how to do this?
I tried:
B_lat= interp1(A_time, A_lat, B_time);
But I get the error "Sample points must be unique and sorted in ascending order," which makes sense because the latitude vector doubles back on itself occasionally.
I also tried:
[B_lat,B_lon] = interpm(A_lat,A_lon,0.0001);
Which works, but then the issue is that I'm just getting a new, larger vector to match to Dataset B.
Also, just for context, originally I was just finding the closest times in A and B and matching the lat/lon and reflectance data that way, but then I realized that means that sometimes I end up with the same lat/lon for different data points. The data was taken on a boat, and I'm comfortable with the interpolation just being linear.
Thanks in advanced for the help! If I've left off any information please let me know.
2 commentaires
Lei Hou
le 25 Fév 2021
Hi Niky,
In your case, it is recommened to use timetable. Timetable has many useful functions when your data is linked to time. I think timetable/synchronize is the thing you are looking for. I tried the following.
ttA=timetable(datetime(A_time,'ConvertFrom',"datenum"),A_latlon);
ttB=timetable(datetime(B_time,'ConvertFrom',"datenum"),B_reflectance);
synchronize(ttA,ttB)
There are some missing time in ttB. After you decide what to do with missing times, synchronize(ttA,ttB) can work without error. You can also refer to synchronize doc to learn more.
Réponses (1)
KSSV
le 25 Fév 2021
load ABdatasets.mat ;
% Remove NaN's from B_time
idx = isnan(B_time) ;
B_time(idx) =[] ;
B_reflectance(idx) =[] ;
A_reflectance = interp1(B_time,B_reflectance,A_time) ;
plot(B_time,B_reflectance,'r')
hold on
plot(A_time,A_reflectance,'b')
legend('B','A')
NOTE: 1. There are few nans in B_time, why?
2. A_time has first few and last few out of range with B_time; so this is extrapolation and cannot be trusted.
2 commentaires
KSSV
le 28 Fév 2021
Then read about knnsearch; this will give you the nearest points. Also have a look on ismember, ismembertol.
Voir également
Catégories
En savoir plus sur Descriptive Statistics dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!