Chosing specific dates/hours from an array - matlab

I have a matrix that has 3months of data or so..Its a 952x1 matrix with the elements in the following format(3 hourly )
Aug-05-2015 03:00:00
Aug-05-2015 06:00:00
Aug-05-2015 09:00:00
Aug-05-2015 12:00:00
Aug-05-2015 15:00:00
Aug-05-2015 18:00:00
Aug-05-2015 21:00:00
Aug-06-2015 00:00:00
Aug-06-2015 03:00:00
Aug-06-2015 06:00:00
I would want to choose say only day timings/ only night or say for august month alone. How do i do that.
Further to my question, if I have a group of .wav files and Im trying to pick only month wise or do daily psd averages etc or chose files belonging to a month how to go about? The following are first 10 .wav files in a .txt file that are read into matlab code-
AMAR168.1.20150823T200235Z.wav
AMAR168.1.20150823T201040Z.wav
AMAR168.1.20150823T201845Z.wav
AMAR168.1.20150823T202650Z.wav
AMAR168.1.20150823T203455Z.wav
AMAR168.1.20150823T204300Z.wav
AMAR168.1.20150823T205105Z.wav
AMAR168.1.20150823T205910Z.wav
AMAR168.1.20150823T210715Z.wav
yyyymmddTHHMMSSZ.wav is part of the format to get sense of some parameters.
Thanks.

Are these datetimes? If so, you can use logical indexing here if you make use of some of the datetime functions. To get the times in August:
t = datetime(2015, 8, 1, 3, 0, 0) + hours(3:3:3000)';
t(month(t) == 8) % Times in August
To get the times that are during the day or night:
t(hour(t) < 12) % Day times
t(hour(t) >= 12) % Night times

Related

Why does DateTime's strftime give the wrong year when I subtract days from dates near the end of a year?

I have to open some logs that have a date in the filename. So I am trying to open all the files through a certain date.
I'm using DateTime. I do:
do
{
$datechoice = $today->strftime('%G%m%d'); #YearMonthDay
$date_for_graph = $today->strftime('%d/%m/%G');
# unshift #Log_Period_Time, "$date_for_graph";
print $datechoice." - ".$date_for_graph."<br>";
$today->subtract(days => 1);
} while($datechoice > 20141107);
But the output shows the wrong year for dates near the end of a year:
20160109 - 09/01/2016
20160108 - 08/01/2016
20160107 - 07/01/2016
20160106 - 06/01/2016
20160105 - 05/01/2016
20160104 - 04/01/2016
20150103 - 03/01/2015 <-- Should be 2016
20150102 - 02/01/2015
20150101 - 01/01/2015
20151231 - 31/12/2015
20151230 - 30/12/2015
20151229 - 29/12/2015
...
20150103 - 03/01/2015
20150102 - 02/01/2015
20150101 - 01/01/2015
20151231 - 31/12/2015
20151230 - 30/12/2015
20151229 - 29/12/2015
20141228 - 28/12/2014 <-- Should be 2015
20141227 - 27/12/2014
20141226 - 26/12/2014
Why is this happening?
Use %Y, not %G, unless you specifically mean to display the date according to the ISO 8601 week number calendar.
(In the ISO calendar, every year is a whole number of weeks running Monday-Sunday. So whenever January 1st isn't a Monday there will be up to three days on one side of it that fall in the "wrong" year by ISO reckoning. For instance, ISO year 2021 started on Monday, January 4th; January 1st through 3rd fell in the last week of 2020. Going the other way, ISO year 2026 will start on Monday, December 29th, 2025, so the last 3 days of that December are already the first week of the next ISO year.)

Unix Time stamp day of the week pattern

If all I have is the unix timestamp and I am not able to use any functions to format it (such as day of the week or date) is there any known pattern by looking at the timestamp to deduce what day of the week it is?
for example perhaps all timestamps that are divisible by 150 are Mondays
The Unix Epoch (Jan 1, 1970, 00:00) was on a Thursday. Specifically it marked the beginning of a Thursday.
The first Monday after the Unix Epoch begins on Jan 5, 1970, 00:00. This is a UNIX timestamp of 96 hours.
The second Monday after the Unix Epoch begins on Jan 12, 1970, 00:00. This is a UNIX timestamp of 264 hours.
Let's assume X is your Unix timestamp in hours. The formula ((X - 96) % (264 - 96)) / 24 will return a zero-based weekday index where 0 is Monday and 6 is Sunday. The formula looks like this:
(X - 96) % 168 / 24 (if X is your timestamp in hours)
(X - 345600) % 604800 / 86400 (if X is your timestamp in seconds)
(X - 345600000) % 604800000 / 86400000 (if X is your timestamp in milliseconds)
If i experiment with exactly this moment, defined by a Unix timestamp of 1466710873523 ms i would get (1466710873523 - 345600000) % 604800000 / 86400000 which is ~3.8 (meaning it's Thursday) (almost Friday though :). Note though that it's Thursday UTC - in certain timezones it might be different so for local time you would need to take timezone offset into account.
From my own observations, the timestamp at midnight GMT ends in 000 every 6 days. The sequence is as follows: 000, 400, 800, 200, 600, 000, 400, 800, 200...
So, today (in UCT) started at 1465948800 and has been Wednesday.
So I know that that tomorrow's starting timestamp will end with 200 etc.
If you count the days from today (1465948800) to your desired date and divide by 6,
if the remainder is 1, the ending will be '200',
2: '600',
3: '000',
4: '400',
5: '800'.
Because a week has 7 days, if this Wednesday ended in 800, next Wednesday will end in 200 and the following wednesday in 600, etc.

MATLAB Cut 3D array of daily data into monthly segments

I have a 1437x159x1253 large matrix (let's call it A) of daily sea ice data for a little over 2 years. I need to write a code that takes the daily data from each month and does mean(A, 3) on it. So basically, 1253 is the t in days. If I start from January, I need to do mean(A,3) of the first 31 days, then the mean(A,3) of February, the next 28 or 29 days. Because the days alternate between 31 and 30 (and 28 or 29 for February), I don't know how to write a code to do this. I can do it manually, but that would take a while.
Thanks!
You can initialize an array containing the number of days in each month, Mon = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] using boolean to check whether it's a leap year (to set Mon(2) = 29). The number of days will help you index each month appropriately, using a loop like:
index=1;
for i=1:12
average = mean(A(:,:,index:(index+Mon(i)-1),3);
index = index+M(i); % Starting location of the next month
end

How can I convert a 5 digit int date and 7 digit int time to a real date?

I've come across some data where the date for today's value is 77026 and the time (as of a few minutes ago) is 4766011. FYI: today is Fri, 18 Nov 2011 12:54:46 -0600
I can't figure out how these represent a date/time, and there is no supporting documentation.
How can I convert these numbers to a date value?
Some other dates from today are:
77026 | 4765509
77026 | 4765003
77026 | 4714129
77026 | 4617107
And some dates from what is probably yesterday:
77025 | 6292509
77025 | 6238790
77025 | 4009544
Ok, with your expanded examples, it would appear the first number is a day count. That'd put this time system's epoch at
to_days(today) = 734824
734824 - 77025 = 657799
from_days(657799) = Dec 29, 1800
The time values are problematic, it looks like they're decreasing (unless you listed most recent first?), but if they are some "# of intervals since midnight", then centi-seconds could be likely. That'd give us a range of 0 - 8,640,000.
4765509 = 47655.09 seconds -> sec_to_time(47655) = 13:14:15
sec_to_time(47650.03) -> 13:14:10
sec_to_time(47141.29) -> 13:05:41
sec_to_time(46171.07) -> 12:49:31

Powershell: get-date & [datetime]::FromFileTime returns different values

Why does get-date & [datetime]::FromFileTime returns different values when converting FileTime? An example:
Get-Date 129442497539436142
returns Thursday, March 10, 0411 4:55:53 PM, but
[datetime]::FromFileTime("129442497539436142")
returns Thursday, March 10, 2011 11:55:53 AM
They produce the same result for me, presumably because I'm in GMT.
(FromFileTime parses the time as UTC, Get-Date appears to be using your local time.)
FileTimes are so-called Ticks. 10 million pass every second. Filetime are 0 at midnight, January 1st 1601 (UTC).
Get-date also have ticks, but the base of ticks used by Get-Date is NOT 1601.
It is January 1st year 1.
You can basically identify the 2 different types of ticks by the first digit.
Filetime ticks starts with digit 1 in the rough range of -100 to + 200 years from now.
The ticks using base on January 1st year 0 starts with 6 in roughly the same time range...
In PowerShell you can get verify Jan. 1st year 1 is tick 0 by typing:
[datetime]'0001-01-01' | Select-Object -property Ticks
Get-Date get ticks from 01/01/0001 00:00
[datetime]::FromFileTimeUTC($a) get ticks from 01/01/1601 00:00
You wrote:
returns Thursday, March 10, 0411 4:55:53 PM, but
returns Thursday, March 10, 2011 11:55:53 AM
The difference is 1600 years
This is an example:
$a = ([datetime]::Now).Ticks - ([DateTime]("01/01/0001 00:00")).Ticks
Get-Date $a # get ticks from 01/01/0001 00:00
$a = ([datetime]::Now).Ticks - ([datetime]("01/01/1601 00:00")).Ticks
[datetime]::FromFileTimeUTC($a) # get ticks from 01/01/1601 00:00
It is based on your local "long date" format.
enter image description here
Either you have to change your system "Long Date"
(OR) Use below command
(get-date).tostring("dd/MM/yyyy")
enter image description here
https://technet.microsoft.com/en-us/library/ee692801.aspx
Regards,
Manikandan Boopathy