Extract rows of matrices with nearest days record

3 次查看(过去 30 天)
Hello, I am re-editing my question once again. I have two matrices as attached. Both have different sizes and 1st, 2nd, 3rd, & 4th value show year, month, day and values in both matrices. I need to extract rows with same year and month however, day of +/-6 days from matrix A and relative to days from matrix B. If two or more days are close in matrices A & B, I should choose the rows corresponding to highest value from both matrices. For example, for the attached matrices the expected output is:
1954 12 22 2,7411 1954 12 28 774
1959 1 3 1,7784 1959 1 10 421
1959 1 24 1,1871 1959 1 24 419
1960 12 4 1,7213 1960 12 8 829
1962 2 12 2,1813 1962 2 15 628
1966 12 24 1,8173 1966 12 27 802
1968 1 15 1,6567 1968 1 17 981
Any help how to code this?

回答(1 个)

KSSV
KSSV 2017-9-12
编辑:KSSV 2017-9-12
doc ismemeber and ismmebrtol for year and month use ismemeber and for days you can use ismemebrtol. It is an easy task.
  1 个评论
Poulomi Ganguli
Poulomi Ganguli 2017-9-12
编辑:Poulomi Ganguli 2017-9-12
ismembertol checks within tolerance limit set by eps. I am not sure how to apply here for my data. I could match year and months using below code:
[~, Matched1_dayYr, Matched2_dayYr] = intersect(A(:, [1:2]), B(:, [1:2]),'rows');
M1_dayYr = A(Matched1_dayYr,[1:4]);
M2_dayYr = B(Matched2_dayYr,[1:4]);
Z1 = [C1 C2];
I found something here: https://www.mathworks.com/matlabcentral/answers/215440-can-you-set-the-tolerance-for-ismembertol-as-a-percentage
however, they are also in decimals.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by