Smallest interval in array
3 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I am attempting to write software that organizes data from a machine that gets triggered multiple times throughout the day. I need to find which times in the day have the highest rate of triggering. In other words, how do I find the intervals with the smallest gaps in time within the data list?
The .xlsx list is attached.
Each row on the list represents an "encounter", and the machine takes a reading of the current time, temp, weight and light level. I need to find out what time interval has the highest rate of triggers.
Any ideas where to start?
Thanks in advance!
2 个评论
Jan
2022-4-27
Start with importing the Excel file to Matlab. Which Matlab version are you using?
Then define, what you exactly want to solve: Are you really looking for the shortest distance between the time values in the 1st column? Or does "interval with highest rate" mean e.g. a certain interval of e.g. 2 hours, which contains the highest number of events? Do the numbers in the other columns matter?
采纳的回答
Star Strider
2022-4-27
I am not certain what the desired result is here.
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/980625/enc_data_samp.xlsx', 'VariableNamingRule','preserve')
Tt = cumsum([0; T1.Time]); % Create Time Vector
Td = diff([0; 0; T1.Time])+eps; % Differences Between Trigger Events
Fr = 1./Td; % Frequency Of Trigger Events
figure
plot(Tt, Td)
grid
xlabel('Time')
ylabel('Trigger Frequency')
I am not certain what the time vector (the independent variable here) actually is (I suspect that it should be ‘time of day’ or something similar), however this is likely the easiest way to determine the frequency of the trigger events as a function of it.
.
8 个评论
Star Strider
2022-4-29
As always, my pleasure!
The ‘idx’ variable is simply the row number of the ‘Trigger’ tally maximum. It can be used to refer to the entire row of the timetable, whatever the timetable contains, so:
maxTriggerRow = TT1c{idx,:}
to display all the variables in that row, or equivalently:
maxTriggerRow = TT1c(idx,:)
to display them with their variable names as well (note the difference between the curly braces {} and parentheses ()).
Here, it just happened to also be equivalent to the hour, and the fprintf statement referred to it as such.
更多回答(1 个)
Thomas Pursche
2022-4-27
Hello Pesach,
when I understood it correctly please find in the following a first approach. Just read in the table, get the specific column and afterwards calculate the distances and minimal entry. Afterwards you can put them into an interval and count them if you want to.
% read in the table
tableData = readtable('enc_data_samp.xlsx');
% access intersting column
timeColumn = tableData.Time;
% calculate distance between each entry
for ii=1:numel(timeColumn)-1
distanceList(ii) = timeColumn(ii+1)-timeColumn(ii);
end
% get the minimal distance
minimalDistance = min(distanceList);
Best regards,
Thomas
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!