Logical lookup between two dates

조회 수: 8 (최근 30일)
Richard Turner
Richard Turner 2018년 5월 24일
댓글: Richard Turner 2018년 5월 25일
I am trying to create a logical lookup between 3 date vectors. Vector a is the lookup value (a date), Vector b is a start date, c is an end date. a is a larger size than b and c, which are both the same size.
I want to return a logical response (1) when a is b<=>c.
The vector size seems to be the main problem when trying to write this. I know there is a simple way to do it, but cant find the answer.
  댓글 수: 3
Jan
Jan 2018년 5월 24일
What does "b<=>c" mean? What exactly is a "date vector"? Please provide some input data.
Richard Turner
Richard Turner 2018년 5월 24일
a is a 282x1 matrix containing sequential dates. b is a 50x1 matrix containing start dates. c is a 50x1 matrix containing end dates. I want to find out how many times the values in 'a' occur between a start date and end date - represented by the same row # in 'b' and 'c'. I don't have any code to share, I've tried indexing b and c using a, but I cant get anything but errors. I'm sure there is an elegant way of doing this...

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2018년 5월 24일
Assuming R2016b or later:
sum(a >= b' & a <= c')
In earlier versions
sum(bsxfun(@ge, a, b') & bsxfun(@le, a, c'))
a, b, c must be date numbers
  댓글 수: 1
Richard Turner
Richard Turner 2018년 5월 25일
Thanks - I'm on 2015b so the second answer worked. You've saved several hours of going around in circles. Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

태그

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by