MATLAB Answers

How to link lat/lon to a variable based on time?

13 views (last 30 days)
Niky Taylor
Niky Taylor on 24 Feb 2021
Commented: KSSV on 28 Feb 2021
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.
Niky Taylor
Niky Taylor on 26 Feb 2021
Hi Lei,
Thanks, this is exactly what I was looking for. I removed the missing time values and associated data from dataset B. I also discovered a few duplicate lat/lon values in dataset A, so I removed those as well. Once I did that, I needed to specify that the variables should be continuous in order for synchronize to interpolate. So I ended up running:
ttA.Properties.VariableContinuity = {'continuous','continuous'};
S = synchronize(ttA,ttB);
Thanks again!

Sign in to comment.

Answers (1)

KSSV on 25 Feb 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) ;
hold on
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.
KSSV on 28 Feb 2021
Then read about knnsearch; this will give you the nearest points. Also have a look on ismember, ismembertol.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by