How to link lat/lon to a variable based on time?
9 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Lei Hou
2021 年 2 月 25 日
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.
回答 (1 件)
KSSV
2021 年 2 月 25 日
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 件のコメント
KSSV
2021 年 2 月 28 日
Then read about knnsearch; this will give you the nearest points. Also have a look on ismember, ismembertol.
参考
カテゴリ
Help Center および File Exchange で Descriptive Statistics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!