how to find nearest date and its corresponding value !

8 ビュー (過去 30 日間)
pankaj mali
pankaj mali 2019 年 10 月 16 日
編集済み: Andrei Bobrov 2019 年 10 月 17 日
Hi,
I have one date/time array(A). and another mat file (AOD) which has first column of date/time and second column has values.
I need find date/time from (AOD) which is nearest to date/time of (A) and the correspoding values from AOD to that date.
and if it find two dates near to date/time from A(for eg two minutes earlier and two minutes later ). it should take earilier datetime !
In my result matrix I should have first column of date/time from file (A) and second column should be values from AOD which were measured at time somewhere near to date/time first colum !
i hope you understand my question. I am adding those two files here.
pardon my english !
  2 件のコメント
Turlough Hughes
Turlough Hughes 2019 年 10 月 16 日
Do you want to round the data to the nearest minute in that case?
If you take times in seconds there are no cases where a time in A is midway between two times in AOD.
pruth
pruth 2019 年 10 月 17 日
what if i just want to round the data to nearest minute !! How can we do it ?

サインインしてコメントする。

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 10 月 16 日
load('date.mat');
load('AOD.mat');
d = datetime(A,'ConvertFrom','datenum');
[lo,i] = ismembertol(AOD_440(:,1),A,1,'DataScale',1/8/60);
TT_out = array2timetable(AOD_440(lo,2),'RowTimes',d(i(lo)),'VariableNames',{'data'});
  3 件のコメント
pankaj mali
pankaj mali 2019 年 10 月 17 日
sir, there is one problem in your solution, in the TT_out what i want is all the dates from A and the values from AOD(:,2) which were measure at closest time from A !
I should get the matrix of size
697*2
Andrei Bobrov
Andrei Bobrov 2019 年 10 月 17 日
編集済み: Andrei Bobrov 2019 年 10 月 17 日
[~,i] = min(abs(AOD_440(:,1) - A(:)));
d = datetime(A,'ConvertFrom','datenum');
TT_out = array2timetable(AOD_440(i,2),'RowTimes',d,'VariableNames',{'data'});
or
T = timetable(AOD_440(:,2),'RowTimes',datetime(AOD_440(:,1),'ConvertFrom','datenum'));
d = datetime(A,'ConvertFrom','datenum');
TT_out = retime(T,d,'nearest');

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by