Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
How to find four most repeated time ntervals?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
In my dataset of car travels, starting time, ending time and value per each interval is given. How to find the most repeated four time intervals in this curve?
For ex, among two, 1st interval "06:30"-"07:30", and second "06:00 - 07:00", then hotspot would be "06:30-07:00". So far, I was able to come till here (tbh with help of this community):
opts = detectImportOptions('StackOverflowDumbCharge.xlsx','TextType','string');
opts.SelectedVariableNames = {'st_timeUCh','end_timeUCh'}; % alternatively {'Var4','Var5'}, or {'Var6','Var7'}
D = readmatrix('StackOverflowDumbCharge.xlsx',opts);
%% CONVERT EACH STRING TO DURATION
D = minutes(duration(D,'InputFormat','hh:mm'));
D(D(:,2)==0,2)=1440; % set 00:00 in the second column to 1440 minutes
%% LOGICAL ARRAY TO FIND THE HOTSPOT
M = false(size(D,1),24*60);
for c = 1:size(D,1)
M(c,D(c,1)+1:D(c,2))=true;
end
hotspotWindow = 45 % minute range of hotspot
freqWindow = movmean(sum(M),[0 hotspotWindow-2],'EndPoints','fill');
[val,idx] = max(freqWindow);
figure(), plot(duration(0,1,0):minutes(1):duration(24,0,0),freqWindow)
hold on, plot(duration(0,idx,0),val,'or')
range = [duration(0,idx,0) duration(0,idx+hotspotWindow,0)]
With this code, it is only finding the the most repeated interval and not considering the values that each interval represent. For example, if interval is 30 mins and value = 0 (4th column [Pevdumb] in the data) then this interval can be disregarded. How it is possible?
0 commentaires
Réponses (1)
Image Analyst
le 20 Sep 2020
Your stackoverflow code does not run. Good thing you came he to where the real experts are:
>> test6
Error using matlab.io.ImportOptions/getNumericSelection (line 437)
Unknown variable name: 'Var2'.
Error in matlab.io.ImportOptions/set.SelectedVariableNames (line 136)
rhs = getNumericSelection(obj,rhs);
Error in test6 (line 2)
opts.SelectedVariableNames = {'Var2','Var3'}; % alternatively {'Var4','Var5'}, or {'Var6','Var7'}
I haven't tried it but have you tried to call unique() on duration, and then pass the result of that as edges into histogram of duration? Something like (untested)
%duration = randi(99, 1, 100000);
edges = unique(duration);
histObject = histogram(duration, edges)
maxCount = max(histObject.Values)
indexes = find(histObject.Values == maxCount)
for k = 1 : length(indexes)
fprintf('max of %d counts occurs between %d and %d.\n',...
maxCount, edges(indexes(k)), edges(indexes(k) + 1));
end
6 commentaires
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!