필터 지우기
필터 지우기

Compare two tables with different length

조회 수: 3 (최근 30일)
Dixi
Dixi 2019년 6월 27일
Hey MatLab users,
i need help to compare different columns from two tables (T1 and T2) with different length for various conditions (date, time, timestep, A, B, C) to cause a result (T2.res).
T2.res should be = 1 for every timestep in T2.timestep if date and time are equal and if the value T1.A (row-1) is not equal or greater than T1.A (row) when T1.B (row) = 1.
T1.date = [20190101; 20190101; 20190101; 20190101; 20190101; 20190101; 20190102; 20190102; 20190102; 20190102; 20190102; 20190102; 20190102; 20190102]
T1.time = [0; 0; 0; 12; 12; 12; 0; 0; 0; 0; 6; 6; 6; 6] % sorted time (0,1,2...)
T1.A = [20; 30; 35; 10; 30; 45; 28; 42; 60; 65; 20; 45; 50; 60] % cumulative value per T1.time
T1.B = [1; 0; 0; 0; 1; 0; 0; 0; 1; 0; 1; 0; 0; 0] % max. one value "1" in T1.B per T1.time value
T2.date = [20190101; 20190101; 20190101; 20190101; 20190101; 20190101; 20190101; 20190102; 20190102; 20190102; 20190102; 20190102; 20190102; 20190102]
T2.time = [0; 0; 0; 12; 12; 12; 12; 0; 0; 0; 6; 6; 6; 6] % sorted time (0,1,2...)
T2.timestep = [1; 2; 3; 1; 2; 3; 4; 1; 2; 3; 1; 2; 3; 4] % sorted timesteps (1,2,3,4...)
T2.C = [15; 5; 25; 10; 20; 40; 5; 13; 39; 55; 8; 1; 24; 20] % different positive values
% Conditions might be like:
% % if T1.date == T2.date && T1.time == T2.time && T1.B == 1 && % "first row in T1" && T1.B
% T2.res = 1;
Result should be:
T2.res = [1; % date: ok, time: ok, T1.B == 1 is the first value in T1.time == 0: ok
1; % date: ok, time: ok, T1.B == 1 is the first value in T1.time == 0: ok
1; % date: ok, time: ok, T1.B == 1 is the first value in T1.time == 0: ok
0; % date: ok, time: ok, T1.B == 1 (row) and T1.A == 30 (row) but T1.A (row-1) == 10 >= T2.C == 10: false
1; % date: ok, time: ok, T1.B == 1 (row) and T1.A == 30 (row) and T1.A (row-1) == 10 < T2.C == 20: ok
1; % date: ok, time: ok, T1.B == 1 (row) and T1.A == 30 (row) and T1.A (row-1) == 10 < T2.C == 40: ok
0; % date: ok, time: ok, T1.B == 1 (row) and T1.A == 30 (row) but T1.A (row-1) == 10 >= T2.C == 5: false
0; % date: ok, time: ok, T1.B == 1 (row) and T1.A == 60 (row) but T1.A (row-1) == 42 >= T2.C == 13: false
0; % date: ok, time: ok, T1.B == 1 (row) and T1.A == 60 (row) but T1.A (row-1) == 42 >= T2.C == 39: false
1; % date: ok, time: ok, T1.B == 1 (row) and T1.A == 60 (row) and T1.A (row-1) == 42 < T2.C == 55: ok
1; % date: ok, time: ok, T1.B == 1 is the first value in T1.time == 12: ok
1; % date: ok, time: ok, T1.B == 1 is the first value in T1.time == 12: ok
1; % date: ok, time: ok, T1.B == 1 is the first value in T1.time == 12: ok
1] % date: ok, time: ok, T1.B == 1 is the first value in T1.time == 12: ok
Thanks!!

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by