MATLAB date conversion and analysis
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Community, I have a data of the following type. There are three columns. The first column is date array. Second column is IP address array and 3rd column is Serial Number array.
Date:['2014/09/14 06:15', '2014/09/14 06:16', '2014/09/14 06:17' .......
IP address : 192.168.1.1 .....'
Unique Number: '2252534' .....
I want to create something like a pivotable on excel. I would like the group the Date into hours. Followed by this grouping I would like to calculate how many times the IP address and Unique Number have appeared during this Hour. I would like to do that for 24 hours. Can you help me on how I can get started to group the hours and count the number of IP address and Unique number within each hour. I would expect the output to be something like following:
Time: 2014-09-14 6:00 to 7:00 Total number of P addresses within this interval: 6 Total number of unique number within this interval : 4
Thx in advance.
Mike
0 Kommentare
Antworten (2)
Iain
am 15 Sep. 2014
Matlab datenum follows the convention of
"day = 1"
"hour = 1/24"
"minute = 1/(24*60)"
If today has the value of 523566123 at midnight (this morning), then 6am to 7am would be 523566123 + 6 * hour to 523566123 + 7 * hour
You can index "logically" i.e.:
accepted_list = times > early_time & times < late_time; % eg, 6am to 7am.
noted_ips = ips(accepted_list);
noted_nums = nums(accepted_list);
That gives you a list of all ip addresses & numbers that were logged, you simply need to count the number that were a specific value: eg.
sum(noted_nums == 5)
sum(strcmpi(noted_ips,'101.101.101.10'))
0 Kommentare
Guillaume
am 15 Sep. 2014
Bearbeitet: Guillaume
am 15 Sep. 2014
- convert the dates to date numbers with datenum
- bin the date numbers with histc and use its 2nd output to find the index of the bin in which each date falls
- use these indices to group the IP and SNs into a cell array, using arrayfun
- use cellfun to operate on each cell array
Depending on the operation, these last two could be replaced by accumarray
e.g:
dndates = datenum(dates);
[~, binindices] = histc(dndates, min(dndates):1/24:max(dndate)+1/24); %to split by hour
groupedip = arrayfun(@(ip, bin) ip(bin), ips, binindices, 'UniformOutput', false);
groupedipcount = cellfun(@(ips) numel(unique(ips)), groupedip);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!