diff --git a/matlab/@dates/ge.m b/matlab/@dates/ge.m index 8f18cf7abe5914049639e7172c5afb88091044d3..625f1bbdf2edc98c77b4771cfbef0afa6d36345c 100644 --- a/matlab/@dates/ge.m +++ b/matlab/@dates/ge.m @@ -43,26 +43,41 @@ if isequal(A.ndat, B.ndat) C = (A==B); idx = find(C==0); for i=1:length(idx) - C(idx(i)) = compare_vectors(@gt, A.time(idx(i),:), B.time(idx(i),:)); + C(idx(i)) = greaterorequal(A.time(idx(i),:), B.time(idx(i),:)); end else - if isequal(A.ndat,1) && isequal(B.ndat,1) - C = compare_vectors(@ge, A.time, B.time); - elseif isequal(A.ndat,1) + if isequal(A.ndat,1) C = NaN(B.ndat,1); for i=1:B.ndat - C(i) = compare_vectors(@ge, A.time, B.time(i,:)); + C(i) = greaterorequal(A.time, B.time(i,:)); end elseif isequal(B.ndat,1) C = NaN(A.ndat,1); for i=1:A.ndat - C(i) = compare_vectors(@ge, A.time(i,:), B.time); + C(i) = greaterorequal(A.time(i,:), B.time); end else C = 0; end end + +function c = greaterorequal(a,b) + if a(1)>b(1) + c = 1; + else + if a(1)<b(1) + c = 0; + else + if a(2)>=b(2) + c = 1; + else + c = 0; + end + end + end + + %@test:1 %$ % Define some dates %$ date_2 = '1950Q2'; diff --git a/matlab/@dates/gt.m b/matlab/@dates/gt.m index 241dd729e046c2d4aabdc6317b48cb9c54c374bf..7960388850c099835cb9de72dbe7ea5ef78285ae 100644 --- a/matlab/@dates/gt.m +++ b/matlab/@dates/gt.m @@ -42,26 +42,40 @@ end if isequal(A.ndat, B.ndat) C = NaN(A.ndat,1); for i=1:A.ndat - C(i) = compare_vectors(@gt, A.time(i,:), B.time(i,:)); + C(i) = greaterthan(A.time(i,:), B.time(i,:)); end else - if isequal(A.ndat,1) && isequal(B.ndat,1) - C = compare_vectors(@gt, A.time, B.time); - elseif isequal(A.ndat,1) + if isequal(A.ndat,1) C = NaN(B.ndat,1); for i=1:B.ndat - C(i) = compare_vectors(@gt, A.time, B.time(i,:)); + C(i) = greaterthan(A.time, B.time(i,:)); end elseif isequal(B.ndat,1) C = NaN(A.ndat,1); for i=1:A.ndat - C(i) = compare_vectors(@gt, A.time(i,:), B.time); + C(i) = greaterthan(A.time(i,:), B.time); end else C = 0; end end + +function c = greaterthan(a,b) + if a(1)>b(1) + c = 1; + else + if a(1)<b(1) + c = 0; + else + if a(2)>b(2) + c = 1; + else + c = 0; + end + end + end + %@test:1 %$ % Define some dates %$ date_2 = '1950Q2'; diff --git a/matlab/@dates/le.m b/matlab/@dates/le.m index 228317228398a2a89dc95c718b43a38757e20b9f..3056785fe7f630b4e48aafb7d6b32b3c7353ffd1 100644 --- a/matlab/@dates/le.m +++ b/matlab/@dates/le.m @@ -43,26 +43,41 @@ if isequal(A.ndat, B.ndat) C = (A==B); idx = find(C==0); for i=1:length(idx) - C(idx(i)) = compare_vectors(@lt, A.time(idx(i),:), B.time(idx(i),:)); + C(idx(i)) = lessorequal(A.time(idx(i),:), B.time(idx(i),:)); end else - if isequal(A.ndat,1) && isequal(B.ndat,1) - C = compare_vectors(@le, A.time, B.time); - elseif isequal(A.ndat,1) + if isequal(A.ndat,1) C = NaN(B.ndat,1); for i=1:B.ndat - C(i) = compare_vectors(@le, A.time, B.time(i,:)); + C(i) = lessorequal(A.time, B.time(i,:)); end elseif isequal(B.ndat,1) C = NaN(A.ndat,1); for i=1:A.ndat - C(i) = compare_vectors(@le, A.time(i,:), B.time); + C(i) = lessorequal(A.time(i,:), B.time); end else C = 0; end end + +function c = lessorequal(a, b) + if a(1)<b(1) + c = 1; + else + if a(1)>b(1) + c = 0; + else + if a(2)<=b(2) + c = 1; + else + c = 0; + end + end + end + + %@test:1 %$ % Define some dates %$ date_2 = '1950Q2'; @@ -79,7 +94,7 @@ end %$ i2 = (d3<=d4); %$ i3 = (d4<=d2); %$ i4 = (d5<=d4); -%$ i5 = (d5<=d5); +%$ i5 = (d5<=d5); %$ %$ % Check the results. %$ t(1) = dyn_assert(i1,1); diff --git a/matlab/@dates/lt.m b/matlab/@dates/lt.m index 3707b6861e71d3a7445203152cda7aceb8c05ef7..97bddcff8aec921db81cc243dcc36a217e361734 100644 --- a/matlab/@dates/lt.m +++ b/matlab/@dates/lt.m @@ -42,26 +42,39 @@ end if isequal(A.ndat, B.ndat) C = NaN(A.ndat,1); for i=1:A.ndat - C(i) = compare_vectors(@lt, A.time(i,:), B.time(i,:)); + C(i) = lessthan(A.time(i,:),B.time(i,:)); end else - if isequal(A.ndat,1) && isequal(B.ndat,1) - C = compare_vectors(@lt, A.time, B.time); - elseif isequal(A.ndat,1) + if isequal(A.ndat,1) C = NaN(B.ndat,1); for i=1:B.ndat - C(i) = compare_vectors(@lt, A.time, B.time(i,:)); + C(i) = lessthan(A.time,B.time(i,:)); end elseif isequal(B.ndat,1) C = NaN(A.ndat,1); for i=1:A.ndat - C(i) = compare_vectors(@lt, A.time(i,:), B.time); + C(i) = lessthan(A.time(i,:),B.time); end else C = 0; end end +function c = lessthan(a,b) + if a(1)<b(1) + c = 1; + else + if a(1)>b(1) + c = 0; + else + if a(2)<b(2) + c = 1; + else + c = 0; + end + end + end + %@test:1 %$ % Define some dates %$ date_2 = '1950Q2';