필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to find four most repeated time ntervals?

조회 수: 2 (최근 30일)
Asrorkhuja Ortikov
Asrorkhuja Ortikov 2020년 9월 20일
마감: MATLAB Answer Bot 2021년 8월 20일
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?

답변 (1개)

Image Analyst
Image Analyst 2020년 9월 20일
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
Asrorkhuja Ortikov
Asrorkhuja Ortikov 2020년 9월 25일
편집: Asrorkhuja Ortikov 2020년 9월 25일
@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 2020년 9월 25일
@ yes yes, apologies, i have edited my question.

이 질문은 마감되었습니다.

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by