Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

How to find four most repeated time ntervals?

2 visualizzazioni (ultimi 30 giorni)
Asrorkhuja Ortikov
Asrorkhuja Ortikov il 20 Set 2020
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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?

Risposte (1)

Image Analyst
Image Analyst il 20 Set 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 Commenti
Asrorkhuja Ortikov
Asrorkhuja Ortikov il 25 Set 2020
Modificato: Asrorkhuja Ortikov il 25 Set 2020
@Image Analst actually I meant, original code works, just I don't know how to find more than one most repeated interval. I couldn't make your code run. Thanks for the answer though
Asrorkhuja Ortikov
Asrorkhuja Ortikov il 25 Set 2020
@ yes yes, apologies, i have edited my question.

Questa domanda è chiusa.

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by