Is there a way to compare just the time portion within a serial date number using IF statements?
Show older comments
Hi - is there any easy way to do a logical compare of serial date numbers of just the time portion by knowing the encoding of matlab's serial date number format? E.g. Suppose you want to get the rows of a matrix that are between 9:30am and 10:30am and you have the serial date number to work with, which contains both date and time. Is there a way to use greater than/less than symbols and perhaps applying a bit mask to do a logial IF statement against time periods you want to see in the matrix?
thank you in advance for any pointers or hints. shaun
Answers (2)
Fangjun Jiang
on 18 Oct 2011
Yes, I think that's the purpose of having datenum. You don't need to know the encoding at all.
StartTime=datenum(2011,11,11,09,30,00);
EndTime=datenum(2011,11,11,11,10,00);
TimeStamp=linspace(StartTime,EndTime);
A=TimeStamp>datenum(2011,11,11,11,00,00);
B=TimeStamp<datenum(2011,11,11,09,50,00);
Walter Roberson
on 19 Oct 2011
Supposing the time to be stored in column 1 of YourRows,
timeB = (9 + 30/60)/24;
timeE = (10 + 30/60)/24;
dayfrac = mod(YourRows(:,1),1); %important!
timeIDX = find(timeB <= dayfrac & dayfrac < timeE);
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!